LoginSignup
2

More than 5 years have passed since last update.

Anemoneのサンプルがリンク一覧取得しかないので,[リンク元,リンク先]って感じで取ってみた。

Posted at
require 'anemone'

File.open("file.dat","w") do |f| 
  Anemone.crawl("http://onod.es") do |anemone|
    anemone.on_every_page do |page|
      unless page.referer == nil 
        links = page.links
        string = ""
        links.each{|link|
          string = "#{page.referer.to_s} #{link.to_s}"
          puts string
          f.puts string
        }   
      end 
    end 
  end 
end

ネストが酷いことになってるけれども,こんな感じでいけます。

  • Anemone::Page#linksのlinksでリンク一覧
  • Anemone::Page#refererで,currentのページ
  • Anemone::Page#urlでpageのリンク

を取得できる…はず。

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
2