Html parsing with Hpricot

G

Greg Ma

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
 
G

Greg Ma

Greg said:
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")
 
J

Juan JosŽé Vidal Agust’ín

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

Juan José Vidal

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,820
Latest member
GilbertoA5

Latest Threads

Top