Ruby + Anemone Web Crawler:正则表达式匹配以一系列数字结尾的URL
假设我正在尝试抓取一个网站,跳过一个像这样结束的页面:
http://HIDDENWEBSITE.com/anonimize/index.php?page=press_and_news&subpage=20060117
我目前正在使用Ruby中的Anemone gem来构建爬虫。 我使用的是skip_links_like方法,但我的模式似乎永远不匹配。 我试图使其尽可能通用,因此它不依赖于子页面而只是=2105925
(数字)。
我试过/=\d+$/
和/\?.*\d+$/
/=\d+$/
但它似乎没有用。
这类似于跳过带有扩展名pdf的网页,来自在Anemone中抓取的zip,但我不能用数字而不是扩展来使其值得。
此外,在http://regexpal.com/上使用pattern =\d+$
将成功匹配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 ...
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
实际上/ /\?.*\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+$/ => #
- 当我使用分组时,如何使用gsub对Ruby正则表达式(regex)进行反向引用?
- ruby正则表达式 – 如何匹配一切直到角色 –
- 使用Look-behind正则表达式(Ruby)的问题
- 如何指定一个适用于英语以外的欧洲语言的正则表达式字符范围?
- 正则表达式validation它的网络路径PHP,jQuery,JavaScript,Ruby
- 在Ruby的“gsub”和Vim的替换命令中,“g”代表什么?
- .gsub(/ \ … /,“”)。worub(/ \(/,“”)。gsub(/ \)/,“”)。gsub(/ \ localhost /,“”)<=这是少数
- Ruby gsub函数
- 如何使用TCPServer序列化对象?