# Hpricot 0.5 -- a fast, forgiving HTML reader

**URL:** <https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079>\
**Category:** Ruby\
**Created:** [February 1, 2007, 4:34am UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079 "2007-02-01T04:34:35Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [February 1, 2007, 4:34am UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/1 "2007-02-01T04:34:35Z")

</div>

Hi, here’s Hpricot 0.5.

gem install hpricot --source [http://code.whytheluckystiff.net](http://code.whytheluckystiff.net)

Hpricot reads HTML pages and works hard to fix them up and give you  
everything you need to wind your way around them and hack them up!  
Inspired by John Resig’s JQuery and Tanaka A.'s HTree.

- Hpricot is standalone. It’s dependant on no other libs, just  
Ruby.
- Hpricot is fast, its parser is written in C with help of the  
wonderful Ragel state machine compiler.
- However, Hpricot also works hard to fix up HTML and pays a small  
penalty to get it right.
- How hard does Hpricot work? My rule is: if Firefox parses it,  
Hpricot should too.

This release has a number of really nice features. The new  
`to_original_html` method will try to preserve as much of the  
original HTML as possible (including its mistakes) while still  
merging in your changes. Also, you can test text nodes with syntax  
like: `//a[text()='Click Me!']`.

Should appear on Rubyforge soon enough. Thank you to all the  
ticketeers and patchistadores out there, especially Leslie Wu who’s  
been punching that commit button like she’s doin the turtle trap!!

\_why

---

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [February 1, 2007, 5:40pm UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/2 "2007-02-01T17:40:40Z")

</div>

On Jan 31, 10:33 pm, \_why [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> - Hpricot is fast, its parser is written in C with help of the  
> like: `//a[text()='Click Me!']`.
> 
> Should appear on Rubyforge soon enough. Thank you to all the  
> ticketeers and patchistadores out there, especially Leslie Wu who’s  
> been punching that commit button like she’s doin the turtle trap!!
> 
> \_why

just downloaded hpricot … no warnings when I run my script.

however, the Rdoc flag is still turned off … documentation please!!!

C:..\Owner\>gem query -n hpricot -r -s http://  
[code.whytheluckystiff.net](http://code.whytheluckystiff.net)"

\*\*\* REMOTE GEMS \*\*\*  
Need to update 2 gems from [http://code.whytheluckystiff.net](http://code.whytheluckystiff.net)  
…  
complete

hpricot (0.5, 0.4.99, 0.4.92, 0.4.90, 0.4.86, 0.4.76, 0.4.59, 0.4.52,  
0.4.47, 0.4.43,  
0.4, 0.3.32, 0.3, 0.2, 0.1)  
a swift, liberal HTML parser with a fantastic library

C:..\Owner\>gem install hpricot --source http://  
[code.whytheluckystiff.net](http://code.whytheluckystiff.net)  
Select which gem to install for your platform (i386-mswin32)

1. hpricot 0.5 (ruby)
2. hpricot 0.5 (mswin32)
3. hpricot 0.5 (ruby)
4. hpricot 0.5 (mswin32)
5. Skip this gem
6. Cancel installation

> 2  
> Successfully installed hpricot-0.5-mswin32

C:\Documents and Settings\Owner\>

RubyGems Documentation Index

hpricot 0.4 [rdoc] [www]  
a swift, liberal HTML parser with a fantastic library

hpricot 0.4.99 [rdoc] [www]  
a swift, liberal HTML parser with a fantastic library

hpricot 0.5 [rdoc] [www]  
a swift, liberal HTML parser with a fantastic library

in all of the listing, only “www” has an active link.

---

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [February 1, 2007, 5:52pm UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/3 "2007-02-01T17:52:40Z")

</div>

On Fri, Feb 02, 2007 at 01:40:06AM +0900, bbiker wrote:

> however, the Rdoc flag is still turned off … documentation please!!!  
> […]  
> Successfully installed hpricot-0.5-mswin32

Oh, I see. This was for the windows one. Well, in the meantime you  
can also use: [http://code.whytheluckystiff.net/doc/hpricot/](http://code.whytheluckystiff.net/doc/hpricot/). Or  
I’ve updated the gem on my personal repository.

\_why

---

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [February 1, 2007, 6:30pm UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/4 "2007-02-01T18:30:44Z")

</div>

On Feb 1, 11:51 am, \_why [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Fri, Feb 02, 2007 at 01:40:06AM +0900, bbiker wrote:
> 
> > however, the Rdoc flag is still turned off … documentation please!!!  
> > […]  
> > Successfully installed hpricot-0.5-mswin32
> 
> Oh, I see. This was for the windows one. Well, in the meantime you  
> can also use:[http://code.whytheluckystiff.net/doc/hpricot/](http://code.whytheluckystiff.net/doc/hpricot/). Or

Thanks for the link to the rdoc documentation.

> I’ve updated the gem on my personal repository.  
> [http://code.whytheluckystiff.net](http://code.whytheluckystiff.net) … isn’t this your personal  
> repository?

just uninstalled and reinstalled Hpricot, still no Rdoc

I don’t mean to be a pain in the a.

Thanks for your patience

Bernard K.

---

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [February 1, 2007, 9:02pm UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/5 "2007-02-01T21:02:58Z")

</div>

Thanks for allow us to change the buffer size. I had stopped using it  
cause  
it kept crashing on me, last night I updated and now it works great 😃

---

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [May 11, 2007, 2:33am UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/6 "2007-05-11T02:33:53Z")

</div>

# This script:

# %W[rubygems open-uri hpricot].each{|x| require x} Hpricot.parse(open(“[http://www.opentable.com/rest\_profile.aspx?rid=3292](http://www.opentable.com/rest_profile.aspx?rid=3292)”).read)

crashes hpricot for me with this error:

# ================= /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.5/lib/hpricot/parse.rb:44:in `scan': ran out of buffer space on element <input>, starting on line 23. (Hpricot::ParseError) from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.5/lib/hpricot/parse.rb:44:in `make’ from /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.5/lib/hpricot/parse.rb:15:in `parse' from (irb):3:in `irb\_binding’ from /usr/local/lib/ruby/1.8/irb/workspace.rb:52:in `irb\_binding’ from /usr/local/lib/ruby/1.8/irb/workspace.rb:52

It’s probably because there’s some insanely large attribute on one of  
the HTML elements.

============

Could hpricot die more gracefully and still parse the document  
leaving only that element invalid when it sees such very large  
attributes?

---

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [May 11, 2007, 9:08am UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/7 "2007-05-11T09:08:32Z")

</div>

On Fri, May 11, 2007 at 09:33:07AM +0900, Ron M wrote:

> /usr/local/lib/ruby/gems/1.8/gems/hpricot-0.5/lib/hpricot/parse.rb:44:in `scan’: ran out of buffer space on element , starting on line 23. (Hpricot::ParseError)

Oh, you can increase the buffer size with: Hpricot.buffer\_size = 262144

\_why

---

<div class="post-metadata">

**Author:** ![S\_why](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/a3d4f5/32.png) [@S\_why](https://www.ruby-forum.com/u/S_why)\
**Post date:** [May 11, 2007, 3:14am UTC](https://www.ruby-forum.com/t/hpricot-0-5-a-fast-forgiving-html-reader/84079/8 "2007-05-11T03:14:55Z")

</div>

Ron M wrote:

> Could hpricot die more gracefully and still parse the document  
> leaving only that element invalid when it sees such very large  
> attributes?

What did why say when you posted this problem to the hpricot mailing  
list?

[http://code.whytheluckystiff.net/hpricot/](http://code.whytheluckystiff.net/hpricot/)
