python mechanize/libxml2dom question

Stefan Behnel stefan_ml at behnel.de
Tue Sep 2 02:06:35 EDT 2008


bruce wrote:
> i've got the following situation, with the following test url:
> "http://schedule.psu.edu/soc/fall/Alloz/a-c/acctg.html#".
> 
> 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.

Stefan



More information about the Python-list mailing list