66
68

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Anemone gem (ruby) で指定したURLだけクロールする方法

Last updated at Posted at 2013-11-14

1行概要

rubyのgem anemonを使って指定した正規表現のURLだけクロールし続けるサンプル

犯行動機

友人がよからぬ事をしようとしていたので援護射撃

方法

crawl.rb
require 'anemone'

Anemone.crawl('http://example.com/start_page.html') do |anemone|

  # クロールするごとに呼び出される
  anemone.focus_crawl do |page|

    # 条件に一致するリンクだけ残す
    # この `links` はanemoneが次にクロールする候補リスト
    page.links.keep_if { |link|
      link.to_s.match(/detail/)
    } 
  
  end
 
  # ここがメインの部分
  anemone.on_every_page do |page|

    # クロールした結果をごにょごにょ
    p page.doc.at('title').inner_html

  end
end

結論

anemoneすごい。

twitterはこちら -> https://twitter.com/tady_jp

66
68
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
66
68

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?