Scrubyt wont work with windows

909 Views Asked by At

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!

1

There are 1 best solutions below

1
On

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