# HTML Parser: Which one is better?

**URL:** <https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573>\
**Category:** Ruby\
**Created:** [May 31, 2007, 9:28am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573 "2007-05-31T09:28:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [May 31, 2007, 9:28am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/1 "2007-05-31T09:28:42Z")

</div>

I’m new to Ruby and need to parse some web pages. I googled “ruby HTML  
parser” and have found several parser avaliable. They all seem good and  
I’m wondering which one is better for me since I’ll have to deal with  
many pages encoded in different encoding, such UTF-8, GB2312 and GBK(For  
Chinese). So please help me. Thanks.

---

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [May 31, 2007, 9:48am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/2 "2007-05-31T09:48:29Z")

</div>

Hpricot is a good starting point.

---

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [May 31, 2007, 11:27am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/3 "2007-05-31T11:27:33Z")

</div>

Dick D. wrote:

> Hpricot is a good starting point.

OK, I got it. Thanks a lot.

---

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [May 31, 2007, 11:37am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/4 "2007-05-31T11:37:48Z")

</div>

On 5/31/07, Dick D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hpricot is a good starting point.

Yeah Hpricot is good, but in general the quality of the Ruby web  
scraping  
choices is pretty impressive. There are variants that are just built on  
top  
of Hpricot but provide an even simpler API.

However your second problem is a bit trickier, where you encounter  
alternate encodings. To do any kind of real work with multiple code  
pages you want to be converting it to unicode (UTF-8) at fetch time.

This isn’t Ruby’s strong point (which is not the same thing as saying  
it can’t do it). But there are multiple choices here - running Ruby on  
JRuby (Java) just for the seamless unicode/codepage support. Hpricot  
is ported to JRuby for instance. I would have a good look at what  
Ruby libraries enable explicit code page conversions.

---

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [June 1, 2007, 8:15am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/5 "2007-06-01T08:15:58Z")

</div>

On 2007-05-31 02:36:57 -0700, “Richard C.”  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) said:

> 

I’ve had great success with this. Just make sure you’re using a later  
version of Ruby 1.8.5+ (that includes the NKF library) and you should  
be fine.

---

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [June 2, 2007, 7:12am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/6 "2007-06-02T07:12:13Z")

</div>

Thank you all for your help.

---

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [June 1, 2007, 3:11am UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/7 "2007-06-01T03:11:18Z")

</div>

Rubyful soup I like. Its highly simple to use although the construction  
of the object from HTML is a bit slower than I’d like. Quite easy to  
use.

---

<div class="post-metadata">

**Author:** ![gsofhon](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/898d66/32.png) [@gsofhon](https://www.ruby-forum.com/u/gsofhon)\
**Post date:** [June 2, 2007, 9:35pm UTC](https://www.ruby-forum.com/t/html-parser-which-one-is-better/105573/8 "2007-06-02T21:35:34Z")

</div>

I’ve used HPricot, and really like it.
