我正在运行Windows XP。我刚安装了最新版本的Ruby(1.9) - Hpricot,Mechanize和Scrubyt安装没有任何问题。我试图使用我能找到的最简单的例子来得到擦洗工作。例如:
require 'rubygems'
require 'scrubyt'
data = Scrubyt::Extractor.define do
fetch 'http://google.com'
title '//head/title'
end
data.to_xml.write($stdout, 1)
但是,我一直收到错误:
C:/ruby/lib/ruby/gems/1.9.1/gems/scrubyt-0.4.06/lib/scrubyt.rb:1: warning: varia
ble $KCODE is no longer effective; ignored
C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': no
such file to load -- jcode (LoadError)
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `
require'
from C:/ruby/lib/ruby/gems/1.9.1/gems/scrubyt-0.4.06/lib/scrubyt.rb:2:in
`<top (required)>'
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:53:in `
require'
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:53:in `
rescue in require'
from C:/ruby/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `
require' from te.rb:2:in `<main>'
我尝试了几个初学者示例,都给出了相同的错误消息。我今天刚开始使用红宝石,所以我无法弄清楚发生了什么。
谢谢!
答案 0 :(得分:1)
似乎scrubyt
不是ruby 1.9-ready,因为jcode
在1.8到deal with encoding issues中使用。从1.9开始,ruby具有更好的编码支持(尤其是utf-8),因此不再需要jcode
。
使用1.9.2:
sebastien@greystones:~/dev$ rvm 1.9.2-head
sebastien@greystones:~/dev$ ruby -v
ruby 1.9.2p94 (2010-12-08 revision 30140) [x86_64-linux]
sebastien@greystones:~/dev$ ruby -e 'require "rubygems"; require "scrubyt"'
/home/sebastien/.rvm/gems/ruby-1.9.2-head/gems/scrubyt-0.4.06/lib/scrubyt.rb:1: warning: variable $KCODE is no longer effective; ignored
<internal:lib/rubygems/custom_require>:29:in `require': no such file to load -- jcode (LoadError)
1.8.7:
sebastien@greystones:~/dev$ rvm 1.8.7-head
sebastien@greystones:~/dev$ ruby -v
ruby 1.8.7 (2010-12-23 patchlevel 330) [x86_64-linux]
sebastien@greystones:~/dev$ ruby -e 'require "rubygems"; require "scrubyt"'
sebastien@greystones:~/dev$
我尝试按如下方式更改Scrubyt文件以解决该问题:
unless "".respond_to? :each_char
$KCODE = "u"
require "jcode"
end
并且还有其他问题...因此需要做更多的工作才能让Scrubyt与ruby 1.9一起运行。
FWIW,您的用例可能更复杂,但您的示例可以使用Mechanize(Scrubyt在内部使用)完成:
require 'rubygems'
require 'mechanize'
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
a.get('http://google.com/') do |page|
puts page.title()
end