On Mon, Feb 28, 2011 at 3:28 AM, Scott B. <sdbarlow / gmail.com> wrote:
> Hi everyone,
>
> I was wondering if anyone could help me. I'm trying to pull text from a
> website using nokogiri and not all the text is not being pulled into my
> variables through XPath.
>
> I have used Firebug (Firefox extension) to pull the correct XPath from
> the page so I'm thinking it should be correct. So far, I have:
>
> variable1 =
> (doc/"/html/body/div[2]/div[7]/div[4]/div[3]/div[6]/div/div/div/div/div/div/div/h2").inner_html
>
> variable 2 =
> (doc/"/html/body/div[3]/div[7]/div[4]/div[3]/div[6]/div/div/div/div/div/div[2]/table/tbody/tr/td[2]/strong").inner_html
>
> variable 3 =
> (doc/"/html/body/div[3]/div[7]/div[4]/div[3]/div[6]/div/div/div/div/div/div[2]/table/tbody/tr/td[2]/strong[2]").inner_html
>
> Now, variable1 is working but I can't get any values out of variable2 or
> variable3.

In my experience, Firebug shows a tbody element as part of the xpath,
even if there is no actual tbody tag in the HTML. In that case,
Nokogiri will fail to find the right element unless you take out the
'tbody/'.

> Is there a different syntax I should be using? To test, I've
> only been outputting to the cli but I want to eventually push these into
> a sqlite3 database.
>
> Anyone have any ideas?
> Cheers.