Scrubyt 不适用于 Windows

发布于 2024-10-19 22:49:16 字数 1224 浏览 0 评论 0原文

我运行的是Windows XP。我刚刚安装了最新版本的 Ruby(1.9) - Hpricot、Mechanize 和 Scrubyt 安装没有任何问题。我尝试使用我能找到的最简单的例子来让 scrapyt 工作。示例:

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>'

我尝试了几个入门示例,都给出了相同的错误消息。我今天刚开始使用 ruby​​,所以我无法真正弄清楚发生了什么。

谢谢!

I am running Windows XP. I just installed the latest version of Ruby(1.9) - Hpricot, Mechanize and Scrubyt installed without any issues. I have tried to work with the simplest examples I could find to get scrubyt working. example :

require 'rubygems'
require 'scrubyt'

data = Scrubyt::Extractor.define do
fetch 'http://google.com'
title '//head/title'
end

data.to_xml.write($stdout, 1)

but, I keep getting the error :

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>'

I have tried several starter examples, all give the same error message. I just started with ruby today, so I can't really figure out what's going on.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你与清晨阳光 2024-10-26 22:49:16

看来 scrubyt 还没有为 ruby​​ 1.9 做好准备,因为 jcode 在 1.8 中使用到 处理编码问题。从 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

It seems scrubyt is not ruby 1.9-ready, as jcode was used in 1.8 to deal with encoding issues. As of 1.9, ruby has a better encoding support (esp. utf-8) and therefore doesn’t need jcode anymore.

With 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)

With 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$ 

I tried to change the Scrubyt files as follows to work around that issue:

unless "".respond_to? :each_char
  $KCODE = "u"
  require "jcode"
end

and got further problems... So more work would need to be done to get Scrubyt to run with ruby 1.9.

FWIW, your use case is more than likely more complicated, but your example can be done with Mechanize (which Scrubyt uses internally):

 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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文