使用Mechanize填写日历?

时间:2014-02-25 20:58:51

标签: ruby mechanize mechanize-ruby

我想填写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)

有什么建议吗?

2 个答案:

答案 0 :(得分:1)

如果字段名称为departureDate,那么这应该有效:

form['departureDate'] = '05/16/2014'

答案 1 :(得分:0)

您没有找到ID为departureDatec12的输入。根据页面的源代码,它是departureDate2。所以试试这个

departure = vegas_form.field_with(:id => 'departureDate2')