Mark Thomas
8/12/2008 6:41:00 PM
On Aug 12, 2:03 pm, Li Chen <chen_...@yahoo.com> wrote:
> Hi all,
>
> I want to find the path to a tag I am interested using hpricot.
> According to the document and examples I think I should use #xpath
> method.
>
> I expect that ruby will return the path as this:
> "/tag1/tag2/div[@id='header']"
>
> but I get the following info:
>
> tag1.rb:4: undefined method `xpath' for nil:NilClass (NoMethodError)
>
> I wonder why method #xpath is not defined?
Look carefully. It's not defined for nil. Which means that
doc.at("header") is returning nil. That's because there are no
elements with the name of "header"; only an attribute. Try using the
css selector "#header".