Ruby 为什么mechanize不搜索此表单?

Ruby 为什么mechanize不搜索此表单?,ruby,mechanize,Ruby,Mechanize,我不熟悉机械化。我试图用搜索词“太极21”搜索一个表单,但它似乎不起作用。页面位于 这是我犯的错误还是表单检测到了机器人 require 'nokogiri' require 'mechanize' agent = Mechanize.new #User Agent masking agent.user_agent_alias = 'Windows Mozilla' #This handles the url page = agent.get('http://www.asus.com/Se

我不熟悉机械化。我试图用搜索词“太极21”搜索一个表单,但它似乎不起作用。页面位于

这是我犯的错误还是表单检测到了机器人

require 'nokogiri'
require 'mechanize'

agent = Mechanize.new

#User Agent masking
agent.user_agent_alias = 'Windows Mozilla'

#This handles the url
page = agent.get('http://www.asus.com/Search/')
pp page

#Lock onto the search box
asus_form = page.form('aspnetForm')

#Prepare a search for our form
asus_form.q = 'TAICHI 21'

#Submit our form
button = asus_form.button_with(:value => "Button1")
page = agent.submit(asus_form, button)

#Output our Pretty Print to text file
pp page
File.open("results.txt","w") do |f|
  PP.pp(page,f)
end

我仔细查看了结果,发现了你的链接。在我的测试中,我改变了代码中的一些东西,但我相信这不会真正改变任何东西。最后一行找到您的链接

agent = Mechanize.new

#User Agent masking
agent.user_agent_alias = 'Windows Mozilla'

#This handles the url
search = 'TAICHI 21'
page = agent.get("http://www.asus.com/Search/?SearchKey=#{search}")

#Output our Pretty Print to text file
File.open("results.txt","w") do |f|
  PP.pp(page.links.find_all{|l| l.text =~ /#{search}/i},f)
end

如果我查看您的
页面所列的链接
,其中有一个链接的文本为“我确认,请带我去那里”。是的,我注意到,当我在浏览器中呈现页面时,它不会出现,尽管在Javascript代码中发现了这一点,我认为它可能是反机器人代码$(#searchinput”).keypress(函数(事件){if(event.keyCode==13){$(#search btn”).click();/*var关键字=$(#searchinput”).val();if(isApplicationPathSite())window.location.href='/'+getWebsite()+'/search/search?SearchKey='+encodeURI(关键字);else window.location.href='/Search/Search?SearchKey='+encodeURI(关键字);返回false;*/});这是一个很好的解决方案,现在需要找到一种方法来使用数组来实现这一点,并在一分钟内将其添加为一个新问题。