我有以下内容:
require 'rubygems'
require 'anemone'
require 'nokogiri'
require 'open-uri'
Anemone.crawl("http://www.findbrowsenodes.com/", :delay => 3) do |anemone|
anemone.on_pages_like(/http:\/\/www.findbrowsenodes.com\/us\/.+\/[\d]*/) do | page |
doc = Nokogiri::HTML(open(page.url))
id = doc.at_css("#n_info #clipnode").text unless doc.at_css("#n_info #clipnode").nil?
File.open("#{node_id}.html", "wb") do |f|
f.write(open(page).read)
end
end
end
所以我试图将每个 URL 保存为一个 html 文件:
File.open("#{id}.html", "wb") do |f|
f.write(open(page).read)
end
但我得到这个错误:
alex@alex-K43U:~/rails/anemone$ ruby anemone.rb /home/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/open-uri.rb:35: in
open': can't convert Anemone::Page into String (TypeError) from /home/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/open-uri.rb:35:in
open' from anemone.rb:27:inblock (3 levels) in <main>' from anemone.rb:26:in
open' from anemone.rb:26:in `block (2 levels) in '
这样做的正确方法是什么?