gpt4 book ai didi

Ruby+Anemone 网络爬虫 : regex to match URLs ending in a series of digits

转载 作者:数据小太阳 更新时间:2023-10-29 07:53:59 24 4
gpt4 key购买 nike

假设我正在尝试抓取一个网站并跳过这样结束的页面:

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但我不能用数字而不是扩展来使它值得。

此外,在 http://regexpal.com/ 上进行测试使用 =\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

关于Ruby+Anemone 网络爬虫 : regex to match URLs ending in a series of digits,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8349599/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com