我想填写 www.vegas.com/lasvegastraveldeals 的日历日期字段。
到目前为止,我似乎无法使value
方法起作用。 这是我的代码:
require 'mechanize'
agent = Mechanize.new
page = agent.get('http://www.vegas.com/lasvegastraveldeals/')
vegas_form = page.form('gs')
vegas_form.q = 'DFW'
departure = vegas_form.field_with(:id => 'departureDatec12')
departure.value = "05/16/2014"
pp page
我收到此错误:
vegas_scraper.rb:9:in `<main>': undefined method `value=' for nil:NilClass (NoMethodError)
有什么建议吗?
如果字段名称departureDate
那么这应该有效:
form['departureDate'] = '05/16/2014'
您找不到 id departureDatec12
的输入。根据页面的源代码,它是 departureDate2
.所以试试这个
departure = vegas_form.field_with(:id => 'departureDate2')