假设我试着抓取一个网站,跳过一个页面,结果如下:
http://HIDDENWEBSITE.com/anonimize/index.php?page=press_and_news&subpage=20060117
我目前正在使用Ruby中的Anemone gem来构建爬虫。我正在使用skip_links_like方法,但我的模式似乎从未匹配过。我试图让它尽可能的通用,这样它就不依赖于子页面,而只依赖于=2105925 (数字)。
我尝试过/=\d+$/和/\?.*\d+$/,但似乎不起作用。
这类似于Skipping web-pages with extension pdf, zip from crawling in Anemone,但我不能用数字代替扩展名。
此外,使用模式=\d+$在http://regexpal.com/上进行测试将成功匹配http://misc.com/test/index.php?page=news&subpage=20060118
编辑:
下面是我的全部代码。我想知道有没有人能看清到底出了什么问题。
require 'anemone'
...
Anemone.crawl(url, :depth_limit => 3, :obey_robots_txt => true) do |anemone|
anemone.skip_links_like /\?.*\d+$/
anemone.on_every_page do |page|
pURL = page.url.to_s
puts "Now checking: " + pURL
bestGuess[pURL] = match_freq( manList, page.doc.inner_text )
puts "Successfully checked"
end
end我的输出如下所示:
...
Now checking: http://MISC.com/about_us/index.php?page=press_and_news&subpage=20110711
Successfully checked
...发布于 2011-12-02 08:03:36
Anemone.crawl(url, :depth_limit => 3, :obey_robots_txt => true, :skip_query_strings => true) do |anemone|
anemone.on_every_page do |page|
pURL = page.url.to_s
puts "Now checking: " + pURL
bestGuess[pURL] = match_freq( manList, page.doc.inner_text )
puts "Successfully checked"
end
end发布于 2011-12-02 07:17:11
实际上,/\?.*\d+$/是有效的:
~> irb
> all systems are go wirble/hirb/ap/show <
ruby-1.9.2-p180 :001 > "http://hiddenwebsite.com/anonimize/index.php?page=press_and_news&subpage=20060117".match /\?.*\d+$/
=> #<MatchData "?page=press_and_news&subpage=20060117"> https://stackoverflow.com/questions/8349599
复制相似问题