Skip to content

Instantly share code, notes, and snippets.

@latpaw
Created June 29, 2012 06:48
Show Gist options
  • Save latpaw/3016342 to your computer and use it in GitHub Desktop.
Save latpaw/3016342 to your computer and use it in GitHub Desktop.
使用spidr采集
require "nokogiri"
require "spidr"
require "open-uri"
def yue
Spidr.site("http://www.somedomain.com") do |spider|
spider.every_html_page do |page|
name = page.title
doc = Nokogiri::HTML(page.body)
doc.css(".left_content2").each do |a|
contents = a.content
Post.create(:name=>name,:content=>contents)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment