我正在尝试在ror中设置机制以填写并提交表单,以便能够抓取下一页的搜索结果。
我已将代码跟踪到错误发生的位置。当我对这样的表单变量进行硬编码时它非常有效:
form['l'] = 'salzburg' # location (works)
form['t'] = 'all:rental' # SELECT 'all:sale' (works)
form['pf'] = 1 # price from (works)
form['pt'] = 800 # price to (works)
form['rf'] = 2 # rooms from (works)
form['rt'] = 5 # rooms to (works)
但是一旦我尝试从变量填写表单,它就不再提交表单了:
pf = @criterium.price_from.to_i.to_s
pt = @criterium.price_to.to_i
rf = @criterium.rooms_from.to_i
rt = @criterium.rooms_to.to_i
puts pf # successfully logs => 1
puts pt # successfully logs => 800
puts rf # successfully logs => 2
puts rt # successfully logs => 5
form['l'] = @criterium.location # location (works)
form['t'] = 'all:rental' # SELECT 'all:sale',
form['pf'] = pf # price from (doesn't work)
form['pt'] = pt # price to (doesn't work)
form['rf'] = rf # rooms from (doesn't work)
form['rt'] = rt # rooms to (doesn't work)
奇怪的是,puts pf,pt,rf,rt命令成功将变量记录到控制台。
但提交失败..
page = agent.submit(form)
没有错误输出,我只是在提交之前和之后通过puts page.title
看到,它保留在同一页面上(=表示表单未提交)。
感谢关于为什么表格没有从变量填充的每个提示。