python mechanize/libxml2dom question

bruce bedouglas at earthlink.net
Tue Sep 2 05:35:47 CEST 2008


hi...

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.

i tried using the following chunk of code with no luck.

#s is the html from the course file
d = libxml2dom.parseString(s, html=1)

#at this point, we should have a vaild "d" representation
print "sdddd=",s

aa=libxml2dom.toString(d)
print "hereeeeee \n\n\n"
print "aa",aa
#sys.exit()

# **** course names

cpath='//table[position()>0]/descendant::td[position()=2][@width="85%"]/../t
d[1]/font/a[2]/text()'

cpath_=[]
cpath_=d.xpath(cpath)

print "len=",len(cpath_)
if len(cpath_)>0:

  for cpath in cpath_:
   #get the coursename info
   cname=cpath.toString()
   print "cpath=",cpath
   print "cname=",cname
   rr="./../../../../../../following-sibling::table//tr[position()>1]"

   rr=cpath.xpath()
   print "rrlen=",len(rr)
   print rr[0].toString()
   sys.exit()


i'm assuming that there's a libxml2node method that will do what i need that
i'm missing...

pointers/comments would be helpful here...

thanks!





More information about the Python-list mailing list