# HTML parsing

**URL:** <https://rubytalk.org/t/html-parsing/9961>\
**Category:** ruby-talk\
**Created:** [2 February 2004 12:42 UTC](https://rubytalk.org/t/html-parsing/9961 "2004-02-02T12:42:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [2 February 2004 12:42 UTC](https://rubytalk.org/t/html-parsing/9961/1 "2004-02-02T12:42:17Z")

</div>

Hi folks,

I need to parse some HTML. I’ve dug around the archives and so on and  
found the best solution to be Ned Konz’s ‘ruby-htmltools’, which  
relies on ‘html-parser’. Both of these projects are not really  
maintained, so I’m wondering what other people currently use.

Cheers,  
Gavin

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Touzery](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Emmanuel\_Touzery](https://rubytalk.org/u/Emmanuel_Touzery)\
**Post date:** [2 February 2004 12:48 UTC](https://rubytalk.org/t/html-parsing/9961/2 "2004-02-02T12:48:00Z")

</div>

Gavin Sinclair wrote:

> Hi folks,
> 
> I need to parse some HTML. I’ve dug around the archives and so on and  
> found the best solution to be Ned Konz’s ‘ruby-htmltools’, which  
> relies on ‘html-parser’. Both of these projects are not really  
> maintained, so I’m wondering what other people currently use.

i was using a home-made solution, but i just decided (this WE) to  
convert it to REXML: I would use HTML tidy (which is already needed for  
~60% of the pages i’m parsing now), and ask tidy to spit out XHTML. i  
think that’s the best (with my home made solution, besides the  
duplication of work of parsing HTML, i needed a list of tags that you  
don’t need to close etc. in XHTML all is done for me… and then i get  
the familiar API of REXML [even though i never used REXML yet :O)]).

i think it’s the best.

emmanuel

---

<div class="post-metadata">

**Author:** ![Robert](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@Robert](https://rubytalk.org/u/Robert)\
**Post date:** [2 February 2004 13:59 UTC](https://rubytalk.org/t/html-parsing/9961/3 "2004-02-02T13:59:57Z")

</div>

“Gavin Sinclair” [gsinclair@soyabean.com.au](mailto:gsinclair@soyabean.com.au) schrieb im Newsbeitrag  
news:541813804653.20040202234122@soyabean.com.au…

> Hi folks,
> 
> I need to parse some HTML. I’ve dug around the archives and so on and  
> found the best solution to be Ned Konz’s ‘ruby-htmltools’, which  
> relies on ‘html-parser’. Both of these projects are not really  
> maintained, so I’m wondering what other people currently use.

Last time I needed that I used some kind of home cooked regexp scanning.  
But I didn’t need a real parser, just wanted to extract some portion from  
the HTML file.

```
robert

```

---

<div class="post-metadata">

**Author:** ![Emmanuel\_Touzery](https://avatars.discourse-cdn.com/v4/letter/e/e274bd/32.png) [@Emmanuel\_Touzery](https://rubytalk.org/u/Emmanuel_Touzery)\
**Post date:** [2 February 2004 12:48 UTC](https://rubytalk.org/t/html-parsing/9961/4 "2004-02-02T12:48:38Z")

</div>

Emmanuel Touzery wrote:

> E) to convert it to REXML: I would use HTML tidy (which is already  
> needed for ~60% of the pages i’m parsing now)

(it was needed for many pages due to sloppy/invalid HTML, that tidy is  
correcting)

emmanuel

---

<div class="post-metadata">

**Author:** ![Gavin\_Sinclair](https://avatars.discourse-cdn.com/v4/letter/g/db5fbb/32.png) [@Gavin\_Sinclair](https://rubytalk.org/u/Gavin_Sinclair)\
**Post date:** [2 February 2004 14:03 UTC](https://rubytalk.org/t/html-parsing/9961/5 "2004-02-02T14:03:12Z")

</div>

The library I mentioned gives you a REXML::Document as well, so I’m  
using REXML for the first time. It’s very good, but I’m struggling to  
really get a grip.

The single most useful improvement to REXML for a beginner, IMO, is  
this: (more) reasonable implementations of #to\_s and/or #inspect on  
Element and Attribute objects.

As it is, I believe every element contains a link to its document,  
which in my case is large, and #inspect spits out thousands of lines  
of rubbish when all I want to see is the element I’m looking at. This  
makes it hard to use in ‘irb’.

(I know, I should start with a small document, but I’m trying to get  
my task done 🙂

Cheers,  
Gavin

> **···**
>
> On Monday, February 2, 2004, 11:48:00 PM, Emmanuel wrote:
> 
> > Gavin Sinclair wrote:
> 
> > > Hi folks,
> > > 
> > > I need to parse some HTML. I’ve dug around the archives and so on and  
> > > found the best solution to be Ned Konz’s ‘ruby-htmltools’, which  
> > > relies on ‘html-parser’. Both of these projects are not really  
> > > maintained, so I’m wondering what other people currently use.
> > 
> > i was using a home-made solution, but i just decided (this WE) to  
> > convert it to REXML: I would use HTML tidy (which is already needed for  
> > ~60% of the pages i’m parsing now), and ask tidy to spit out XHTML. i  
> > think that’s the best (with my home made solution, besides the  
> > duplication of work of parsing HTML, i needed a list of tags that you  
> > don’t need to close etc. in XHTML all is done for me… and then i get  
> > the familiar API of REXML [even though i never used REXML yet :O)]).
