Skip to content

Instantly share code, notes, and snippets.

@mccxj
Created June 24, 2009 11:30
Show Gist options
  • Save mccxj/135190 to your computer and use it in GitHub Desktop.
Save mccxj/135190 to your computer and use it in GitHub Desktop.
# backup from uptolife.blogspot.com
$KCODE='gbk'
require 'rubygems'
require 'nokogiri'
require 'open-uri'
gem 'activerecord','2.1.2'
require 'active_record'
require 'thread'
ActiveRecord::Base.establish_connection(:adapter => 'mysql',
:database => 'test', :host => '192.168.1.184', :username => 'root',
:password => '123456', :encoding => 'utf8')
# id,title,body,tag,post_on,link
class Post < ActiveRecord::Base
end
Post.all(:conditions => 'post_on is null', :order => "id", :limit => 50).each do |post|
begin
page = Nokogiri::HTML(open(post.link))
p date_header = page.search('h2.date-header').first.text
post.post_on = Date.strptime(date_header.split(' ').first,'%Y年%m月%d日')
post.save
rescue => e
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment