【问题标题】:anemone print links on first page第一页上的海葵打印链接
【发布时间】:2013-03-27 05:52:34
【问题描述】:

想看看我做错了什么。在这里。

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

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

我做错了什么?

编辑:不输出任何内容。

【问题讨论】:

  • 好的,代码的输出是什么?
  • 你能显示你在控制台中输入的命令行命令吗?
  • ruby crawl.rb stackoverflow.com

标签: ruby anemone


【解决方案1】:

这对我有用

 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-04
    • 2011-12-31
    • 1970-01-01
    相关资源
    最近更新 更多