wozhidao 发表于 2013-2-7 19:04:18

采集碰到的一大堆麻烦事

今天想采集一个网站,准备拿ruby来练练,结果碰到一大堆麻烦事,C#代码写的是多点,感觉还是顺手些。
由于不想写正则,找了几个插件试
(1)scrapi,顺利安装完成,确根本采集不到信息
require 'scrapi'require 'open-uri'task :dream => :environment do      url='http://www.hushibo.cn'      html = open(url).read          puts html end 
就这就报一大堆错,实在没信心写下去了,换下一个 Hpricot
gem install hpricot 
结果在windows ruby1.9.1上装不了,万股无奈下只好用nokogiri,用的人确很少,文档太难找,http://nokogiri.org/Nokogiri/XML/NodeSet.html硬着头皮看了半天,总算知道了点皮毛,把我的采集任务算是完成了
require 'nokogiri'require 'open-uri'task :dreamtype => :environment do   doc = Nokogiri::HTML(open('http://www.hushibo.cn'))    tpes = []    doc.css("table.txt>td:nth-child(12)>a").each do |link|      #puts link.contenttpes.push(link.content)    end    #puts doc    tpes.each do |t|      #puts tpes.length      Dream.create(:parent_id => 6,:name => t)    endend 
页: [1]
查看完整版本: 采集碰到的一大堆麻烦事