我想知道是否可以使用数组进行多个机械化查询?以下代码减去数组适用于单个但不是多个查询。
require 'nokogiri'
require 'mechanize'
agent = Mechanize.new
#User Agent masking
agent.user_agent_alias = 'Windows Mozilla'
#Array of keywords to search
search = Array.new
search << 'TAICHI 21'
search << 'S56CA'
#Take our search array, insert it into a query
agent.get("http://www.asus.com/Search/?SearchKey=#{search}")
#This handles the url
File.open("results.txt","w") do |f|
PP.pp(page.links.find_all{|l| l.text =~ /#{search}/i},f)
end
第二次尝试
require 'nokogiri'
require 'mechanize'
agent = Mechanize.new
#User Agent masking
agent.user_agent_alias = 'Windows Mozilla'
#Array of keywords to search
search = [ 'S56CA', 'TAICHI 21' ]
#Take our search array, insert it into a query
agent.get("http://www.asus.com/Search/?SearchKey=#{search}")
File.open("results.txt","w")
#This handles the url
search.each do |f|
results.txt << PP.pp(page.links.find_all{|l| l.text =~ /#{search}/i},f)
end