Can I copy a text on a webpage and paste it in a text file?

天大地大妈咪最大 提交于 2019-12-24 09:15:08

问题


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) }


来源:https://stackoverflow.com/questions/11325947/can-i-copy-a-text-on-a-webpage-and-paste-it-in-a-text-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!