我想使用capybara来获取具有列表的远程站点的内容,并且列表的内容是由javascript生成的,我该如何获取这些内容? 要求“水豚” 需要“capybara / mechanize” 需要“capybara-webkit” 需要“ko_spider / proxy / proxy”
module KoSpider
class CoreSpider
include Capybara::DSL
def initialize(wait=10)
proxy = Proxy.new
Capybara.configure do |conf|
conf.run_server = false
conf.app = ''
conf.javascript_driver = :webkit
conf.default_driver = :mechanize
conf.current_driver = :mechanize
conf.default_wait_time = wait
conf.ignore_hidden_elements = false
conf.current_session.driver.browser.agent.user_agent_alias = 'Mac Safari'
conf.current_session.driver.browser.agent.set_proxy(proxy.host,proxy.port)
end
super()
end
def get_proxy_by_url(url)
visit(url)
page.all(:css, 'table.tb tbody tr').each do |tr|
host = ''
port = ''
tr.all('td').each_with_index do |td,idx|
host = td.text if idx == 1
port = td.text if idx == 2
end
puts "=========#{host}:#{port}==========="
end
end
end
end
我想让主机和端口在this page使用方法get_proxy_by_url,但是在端口的列中,所有这些都是由javascripts生成的,我该如何获取它们
正如您所看到的,在get_proxy_by_url方法中,我尝试获取端口的文本,但我无法获取这些,我想知道水豚是否可以获取它们