【发布时间】:2012-03-06 17:36:23
【问题描述】:
我一直在研究一个 Ruby 脚本,它将数据输入到搜索字段中,然后需要单击输入按钮。通过查看“pp”,我的数据正确输入到搜索字段中。我遇到的问题是单击“输入”按钮。正在发生的事情是它没有向前移动它只是刷新当前屏幕。当我通过 IE 手动访问相关网站时,输入搜索数据并在我的键盘上按 Enter,它不会滚动到搜索屏幕;我必须在 enter 上单击鼠标才能使其向前移动。如果我使用 Chrome 并使用键盘输入执行相同的任务,那么它会打开一个新选项卡。我如何以编程方式获得此进展?
这是我的代码:
require 'rubygems'
require 'mechanize'
agent = Mechanize.new
agent.verify_mode = OpenSSL::SSL::VERIFY_NONE
page = agent.get('https://somewebsite.com')
check_form = page.form
check_form['ct100$MainContent$txtNumber'] = 'J520518'
pp page
page = agent.submit(check_form, check_form.buttons.first)
pp page
page.links.each do |link|
puts link.text
end
这里是输出的片段:
...
<forms
#<Mechanize::Form
<name nil>
<method "POST">
<action "">
<fields
...
[field:0xb627a0 type: name:ct100$MainContent$txtNumber value: J520518]>
...
<buttons
[submit:0xb6d8ac type: submit name: ct100$MainContent$btnEnter value: Enter]
}>}>
...
<forms
#<Mechanize::Form
<name nil>
<method "POST">
<action "">
<fields
...
[field:0xb627a0 type: name:ct100$MainContent$txtNumber value: ]>
...
<buttons
[submit:0xb6d8ac type: submit name: ct100$MainContent$btnEnter value: Enter]
一如既往,非常感谢您的帮助!
【问题讨论】: