From: Drew Raines Date: 2007-04-19T05:00:06+09:00 Subject: Re: Hpricot getting a table lrlebron@gmail.com wrote: > This gets me a lot closer to what I need. > I'm having some problems with syntax. If I'm reading the docs > correctly map returns an array. So I should be able to do something > like > > arrTables = (doc/"tables").map > > And then access each table individually. For example > > arrTables[0] Array#map wasn't particularly relevant in my example; I just used it to iterate #puts over the result of (doc/"table"). The real lesson to glean from my response is that: (doc/"table") is much nicer than: doc.search("/html/body/table[5]/tr/td[2]/div[3]/table/tr/td/div[1]/table") ...which, like Peter alluded to, is fairly meaningless to us because we don't know what the full original HTML looks like. You can grab the s from the snippet you provided with just a CSS-style search[1]. FWIW, if you have any control over the markup, you can simply add some unique classes to the tables you want:
...
...
...
Then do: (doc/"table.foo") That'll work regardless of how many s are on the page. -Drew Footnotes: [1] http://lnk.nu/code.whytheluckystiff.net/e7m