Can I copy a text on a webpage and paste it in a t

2019-07-31 09:22发布

问题:

I have a webpage which dynamically displays a text which I want to copy into a text file using watir-webdriver or any other additional gems. Is it possible?? If yes, how??

Thanks in advance..

回答1:

If you are talking about web-scraping try Nokogiri



回答2:

I will assume that you you have HMTL like this:

<div id="tehcodez">teh codez</div>

This would save text teh codez to file tehcodez.txt (not tested):

text = browser.div(:id => "tehcodez").text
File.open("tehcodez.txt", "w") {|file| file.write(text) }