Last active
November 30, 2016 14:20
-
-
Save yurakawa/632a6d4b69429e775484 to your computer and use it in GitHub Desktop.
anemone用テンプレートファイル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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