Jackson Henley
Jackson Henley

Reputation: 1531

How to "crawl" only the root URL with Anemone?

In the example below I would like anemone to only execute on the root URL (example.com). I am unsure if I should apply the on_page_like method and if so what pattern I would need.

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

Upvotes: 3

Views: 1609

Answers (1)

sunnyrjuneja
sunnyrjuneja

Reputation: 6123

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

You can also specify the following in the options hash, below are the defaults:

# 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

My personal experience is that Anemone was not very fast and had a lot of corner cases. The docs are lacking (as you have experienced) and the author doesn't seem to be maintaining the project. YMMV. I tried Nutch shortly but didn't play aroud as much but it seemed faster. No benchmarks, sorry.

Upvotes: 6

Related Questions