建立了一个 rake 任务,在 MacOS 下运行正常,在 linux centOS5 下不工作,也不报错,什么原因?请高手帮忙看看,这是部分代码:
task :grab do
require 'rubygems'
require 'activerecord'
require 'nokogiri'
require 'open-uri'
require 'article'
@article = Article.new
@article.class = "1"
@article.time = Time.gm(*Time.now)
#上面代码正常(数据可正常存入数据库),以下代码在 MacOS 下运行正常,在 linux centOS5 下不工作:
link="http://www.cnblogs.com/ilazysoft/archive/2011/11/04/2236337.html"
doc = Nokogiri::HTML(open(link))
doc.css("#single a,").each do |a|
reg = /更多详情/
if a.text =~ reg
@article.olink = a[:href]
break
end
end
doc.css("#single p").each do |p|
reg = /.{140,}/
if p.text =~ reg
@article.description = p.text
break
end
end
@article.save