海葵在第一页打印链接

问题描述:

想看看我做错了什么。这里。海葵在第一页打印链接

我需要在父页上打印链接,即使它们是针对另一个域的。然后出去。

require 'anemone' 
url = ARGV[0] 
Anemone.crawl(url, :depth_limit => 1) do |anemone| 
    anemone.on_every_page do |page| 
     page.links.each do |link| 
      puts link 
     end 
    end 
end 

我在做什么不对?

编辑:无输出。

+0

OK,有什么代码的输出? – 2013-03-27 05:55:23

+0

你可以显示你在控制台中点击的命令行命令吗? – 2013-03-27 06:16:42

+0

红宝石crawl.rb http://www.stackoverflow.com – tven 2013-03-27 17:58:16

这为我工作

require 'anemone' 
    require 'optparse' 
    file = ARGV[0] 
    File.open(file).each do |url| 
     url = URI.parse(URI.encode(url.strip)) 
     Anemone.crawl(url, :discard_page_bodies => true) do |anemone| 
      anemone.on_every_page do |page| 
        links = page.doc.xpath("//a/@href") 
        if (links != nil) 
          links.each do |link| 
            puts link.to_s 
          end 
        end 
      end 

     end 
    end