我有一个半小时前曾经工作过的小爬行器/屏幕抓取脚本,但现在它不再工作了。我检查了页面源代码中reg表达式的html和css值,但它们仍然是相同的,所以从这个角度来看,它应该起作用。任何猜测?红宝石屏幕抓取脚本中的问题
require "open-uri"
# output file
f = open 'results.csv', 'w+'
# output string
results = ""
begin
# crawl first 20 pages
for i in (1..20)
open("http://www.example-#{i}.com") {|url|
# check each line using regular expression
url.each_line { |line|
if line =~ /class=\"L1g\" onclick=\"s_objectID=\'foobar\'\">([^<]+)<\/a><\/h3><\/li>/
# if regular expression matches then add to results
results += $1 + "\n"
end
}
}
end
ensure
# write to and close file
f.print results
f.close
end
你说它不起作用,会发生什么? – mikej 2010-10-18 06:57:06
用于打破Stack Overflow的语法高亮显示。它产生了什么异常消息?另外,你有没有尝试过[如何调试ruby脚本?]中提到的任何调试方法(http://stackoverflow.com/questions/3955688/how-do-i-debug-ruby-scripts) – 2010-10-18 06:57:52
因此,页面是与往常一样,并且它在过去有效。你升级了Ruby吗? – Sirupsen 2010-10-18 08:48:57