3

在下面的示例中,我希望 anemone 仅在根 URL (example.com) 上执行。我不确定我是否应该应用 on_page_like 方法,如果是,我需要什么模式。

  require 'anemone'
    Anemone.crawl("http://www.example.com/") do |anemone|
      anemone.on_pages_like(???) do |page|
        # some code to execute
      end
    end
4

1 回答 1

6
require 'anemone'
Anemone.crawl("http://www.example.com/", :depth_limit => 1) do |anemone|
  # some code to execute
end

您还可以在选项哈希中指定以下内容,以下是默认值:

# run 4 Tentacle threads to fetch pages
:threads => 4,
# disable verbose output
:verbose => false,
# don't throw away the page response body after scanning it for links
:discard_page_bodies => false,
# identify self as Anemone/VERSION
:user_agent => "Anemone/#{Anemone::VERSION}",
# no delay between requests
:delay => 0,
# don't obey the robots exclusion protocol
:obey_robots_txt => false,
# by default, don't limit the depth of the crawl
:depth_limit => false,
# number of times HTTP redirects will be followed
:redirect_limit => 5,
# storage engine defaults to Hash in +process_options+ if none specified
:storage => nil,
# Hash of cookie name => value to send with HTTP requests
:cookies => nil,
# accept cookies from the server and send them back?
:accept_cookies => false,
# skip any link with a query string? e.g. http://foo.com/?u=user
:skip_query_strings => false,
# proxy server hostname
:proxy_host => nil,
# proxy server port number
:proxy_port => false,
# HTTP read timeout in seconds
:read_timeout => nil

我个人的经验是,Anemone 的速度不是很快,而且有很多极端情况。缺少文档(正如您所经历的那样),并且作者似乎没有维护该项目。YMMV。我很快尝试了Nutch,但没有玩太多,但它似乎更快。没有基准,对不起。

于 2013-01-09T03:28:40.470 回答