HTMLDocument and Xpath

Alan Kennedy alanmk at hotmail.com
Fri Feb 3 07:08:51 EST 2006


[swilson at acs.on.ca]
> Hi, I want to use xpath to scrape info from a website using pyXML but I
> keep getting no results.
>
> For example, in the following, I want to return the text "Element1" I
> can't get xpath to return anything at all.  What's wrong with this
> code?

Your xpath expression is wrong.

> test = Evaluate('td', doc_node.documentElement)

Try one of the following alternatives, all of which should work.

test = Evaluate('//td', doc_node.documentElement)
test = Evaluate('/html/body/table/tr/td', doc_node.documentElement)
test = Evaluate('/html/body/table/tr/td[1]', doc_node.documentElement)

HTH,

Alan.




More information about the Python-list mailing list