views:

917

answers:

6

I'm trying to get Hpricot working with Rails on my dev machine.

I've installed Hpricot [0.8.1] using the standard 'gem install hpricot' and confirmed it works fine with my standard Ruby installation [1.8.7]; however when I try the same with my Rails [2.1.0] installation, I get an error -

TypeError: superclass mismatch for class BogusETag from /usr/lib/ruby/1.8/hpricot/tag.rb:130

Seems like there's some kind of conflict, but googling the error hasn't turned up any useful information.

Any ideas ? Thanks in advance.

A: 

Try using Hpricot in a irb session, because i don't think this should generally happen



irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'hpricot'
=> true
irb(main):003:0> doc=Hpricot.parse("<html><head><title>test</title></head><body> Wooo Hooo </body></html>")
=> # {elem  {elem  "test" } } {elem  " Wooo Hooo " } }>
irb(main):004:0> doc.search('title')
=> # "test" }]>
irb(main):005:0> doc.search('title').text
=> "test"

That means your Hpricot is working fine. And the problem is in way you are using it in Rails. ( It would be easier if you could paste your code ).

I had few issues with Hpricot(0.8.1) earlier, had to switch back to 0.6.164 version. you can try that if you want.

HTH

Rishav Rastogi
A: 

If you're free to choose your HTML parsing library, switch it. Why, the creator of Hpricot, recently posted that you should better use Nokogiri instead of HPricot, nowadays.

bb
Can you post a link citing his explanation? You've given no compelling reason in your answer for the choice of Nokogiri.
Oliver N.
It's unmaintained. The creator of HPricot, called "Why the lucky stiff" or just "why" or "_why" recently deleted all of his online accounts and domains. The former homepage for hpricot was http://code.whytheluckystiff.net/hpricot/ (not working!). See 3rd paragraph of http://en.wikipedia.org/wiki/Why_the_lucky_stiff or http://news.ycombinator.com/item?id=773106 for reference. The community created mirrors for his works, e.g. http://github.com/whymirror/hpricot/tree/master for hpricot. Still the code is more or less unmaintained. Why's Twitter quote to switch to Nokogiri is no longer available.
bb
A: 

Hi, I've got the same error right now, I transfer my application from macOS X leopard to Ubuntu and get this error. How did you solve it ?

A: 

SOLVED -- I was able to solve by reverting to hpricot version 0.6 (from 0.8.1)

Marcus Mitchell
+1  A: 

This error occurs because there is no compiled library for the platform. To solve this for your current hpricot version, go to your rails directory dir and do the following (this assumes you are using an unpacked gem - this problem wouldn't arrise otherwise, unless your OS has been upgraded since installing the gem):

cd vendor/gems/hpricot-0.6/ext/hpricot_scan/
ruby extconf.rb
make

Then copy the compiled library to the correct platform dir for your system. Each version of OS X has a slightly different platform name, so mine (Snow Leopard) appears as:

ruby-1.8.6-p383 > RUBY_PLATFORM
 => "i686-darwin10.0.0"

This means I needed to copy the file "hpricot_scan.bundle" (OS X uses bundles for shared libraries, on Linux that would be "hpricot_scan.so") to the following directory, creating it if necessary:

vendor/gems/hpricot-0.6/lib/i686-darwin10.0.0/

Substitute the appropriate platform name (puts RUBY_PLATFORM from irb) for your machine.

William Roe
A: 

Execute Below command and its works

gem install hpricot --platform=mswin32

Amit