在使用Mechanize(在Ruby中)自动输入搜索字段并自动单击提交按钮后,我无法返回结果页面。
问题是返回了3秒的加载页面,而不是几秒钟后加载的实际结果页面。
在那里睡觉显然是行不通的。
require 'mechanize'
agent = Mechanize.new
url = 'https://www.intelius.com'
agent.get(url) do |page|
form = page.forms.first
username_field = form.field_with(:id => "peopleSearch_firstName")
username_field.value = "John"
password_field = form.field_with(:id => "peopleSearch_lastName")
password_field.value = "Lee"
city_state_field = form.field_with(:id => "peopleSearch_cityState")
city_state_field.value = "Van Nuys, CA"
page_logged_in = form.submit
sleep(5)
puts page_logged_in.body
end