python mechanize/libxml2dom question

Stefan Behnel stefan_ml at
Tue Sep 2 08:06:35 CEST 2008

bruce wrote:
> i've got the following situation, with the following test url:
> "".
> i can generate a list of the tables i want for the courses on the page.
> however, when i try to create the xpath query, and plug it into the xpath
> within python, i'm missing something. if i have a parent xpath query, that
> generates a list of results/nodes... how can i then use the individual
> parent node, and trigger off of it, to get further information.
[code example stripped]

You should really use lxml. It has callable XPath objects that feel like
Python functions, and its Element objects have a getparent() method that gets
you to the parent of the node. Plus, text strings that you get back from an
XPath evaluation also have a getparent() method that returns the Element
object that holds the text. I think that's what you were looking for.


More information about the Python-list mailing list