# Html parsing with Hpricot

**URL:** <https://www.ruby-forum.com/t/html-parsing-with-hpricot/189894>\
**Category:** Ruby\
**Created:** [June 9, 2010, 3:35pm UTC](https://www.ruby-forum.com/t/html-parsing-with-hpricot/189894 "2010-06-09T15:35:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [June 9, 2010, 3:35pm UTC](https://www.ruby-forum.com/t/html-parsing-with-hpricot/189894/1 "2010-06-09T15:35:30Z")

</div>

Hi,  
I need to parse a wonderful html page full of tables everywhere!  
Obviously I am using Hpricot to parse my html, and this what I’ve done  
so far.  
But now I stuck :S

page.search("#profile \> table \> tr")[1].at(“td”).at(“table”)

In my table element I now need to fetch childs “tr”, so I’ve done this:

page.search("#profile \> table \>  
tr")[1].at(“td”).at(“table”).search(“tr”)

But this isn’t working because it fetches the childs and inside the  
childs.  
HOw can I fetch just the childs elements?

Greg

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [June 9, 2010, 3:48pm UTC](https://www.ruby-forum.com/t/html-parsing-with-hpricot/189894/2 "2010-06-09T15:48:56Z")

</div>

Greg Ma wrote:

> Hi,  
> I need to parse a wonderful html page full of tables everywhere!  
> Obviously I am using Hpricot to parse my html, and this what I’ve done  
> so far.  
> But now I stuck :S
> 
> page.search("#profile \> table \> tr")[1].at(“td”).at(“table”)
> 
> In my table element I now need to fetch childs “tr”, so I’ve done this:
> 
> page.search("#profile \> table \>  
> tr")[1].at(“td”).at(“table”).search(“tr”)
> 
> But this isn’t working because it fetches the childs and inside the  
> childs.  
> HOw can I fetch just the childs elements?
> 
> Greg

This made the trick  
page.search("#profile\_bandschedule \> table \>  
tr")[1].at(“td”).at(“table”).search("/tr")

---

<div class="post-metadata">

**Author:** ![gregm](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/bc79bd/32.png) [@gregm](https://www.ruby-forum.com/u/gregm)\
**Post date:** [June 9, 2010, 4:57pm UTC](https://www.ruby-forum.com/t/html-parsing-with-hpricot/189894/3 "2010-06-09T16:57:43Z")

</div>

It’s not so obvious that you are using Hpricot. You could use Nokogiri  
too.  
I prefer Nokogiri ([http://nokogiri.org/](http://nokogiri.org/))

Juan JosÃ© Vidal

El 09/06/10 15:35, Greg Ma escribiÃ³:
