Skip to content

Instantly share code, notes, and snippets.

@yurakawa
Last active November 30, 2016 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yurakawa/632a6d4b69429e775484 to your computer and use it in GitHub Desktop.
Save yurakawa/632a6d4b69429e775484 to your computer and use it in GitHub Desktop.
anemone用テンプレートファイル
require 'anemone'
urls = [
"http://example.com/",
"http://example2.com/",
]
cookies = {
}
opts = {
:user_agent => 'MyCrawler/0.00',
:skip_query_strings => true,
:delay => 1,
:storage => Anemone::Storage.MongoDB,
:depth_limit => 1,
# :accept_cookies => true,
# :cookies => cookies,
:proxy_host => 'htt://example-proxy.com',
# :proxy_host => 'http://your_userid:your_password@example-proxy.com',
:proxy_port => '8888'
}
# 巡回対象サイトのURLを指定
Anemone.crawl(urls , opts) do |anemone|
# 除外対象ページのURLパターンを指定
anemone.skip_links_like /除外対象のURLパターン/
# 巡回対象ページのURLを指定
anemone.focus_crawl do |page|
page.links # => Array of links
end
# 正規表現で一致したページのみ処理
anemone.on_pages_like(/処理対象のURLパターン/) do |page|
# ページに対する処理の記述
end
# すべてのページに対しての処理
anemone.on_every_page do |page|
# ページに対する処理の記述
end
# ストレージに対する処理
anemone.after_crawl do |page|
# ストレージに対する処理の記述
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment