ruby – 是否可以使用机器人打开浏览器,手动操作页面,然后继续使
发布时间:2020-12-16 19:11:13 所属栏目:百科 来源:网络整理
导读:我正在使用 Ruby,Selenium WebDriver和Nokogiri从网页中检索数据.加载正确的HTML后,我打印某个类的内容. 例如, require "selenium-webdriver"require "nokogiri"browser = Selenium::WebDriver.for :chromebrowser.get "https://jsfiddle.net"doc = Nokogiri
我正在使用
Ruby,Selenium WebDriver和Nokogiri从网页中检索数据.加载正确的HTML后,我打印某个类的内容.
例如, require "selenium-webdriver" require "nokogiri" browser = Selenium::WebDriver.for :chrome browser.get "https://jsfiddle.net" doc = Nokogiri::HTML.parse(browser.page_source) doc.css('.aiButton').map(&:text).join(',') 到目前为止,我发现最困难的部分是正确加载正确的HTML.例如,我想要的内容可能被某些javascript隐藏,或者可能位于不同的页面上. 是否可以使用Selenium加载页面,然后手动操作页面以显示正确的HTML,然后允许机器人完成并打印它应该的内容? 解决方法
您可以使用Selenium与网页进行交互 – 填写表单字段,单击按钮等.您甚至可以执行自己的javascript代码.
Selenium cheat sheet 编辑: 使用pry停止代码执行,以便您可以手动操作网页. # Code for starting Selenium session and opening the web page ... # Use pry to stop the code execution. # Resume the program using command 'exit' in the pry context require 'pry'; binding.pry # Code to get results after you manually manipulate the web page ... (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |