473,779 Members | 2,089 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

python mechanize/libxml2dom question

hi...

i've got the following situation, with the following test url:
"http://schedule.psu.ed u/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.pars eString(s, html=1)

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

aa=libxml2dom.t oString(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(cpat h_)
if len(cpath_)>0:

for cpath in cpath_:
#get the coursename info
cname=cpath.toS tring()
print "cpath=",cp ath
print "cname=",cn ame
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!
Sep 2 '08 #1
1 1940
bruce wrote:
i've got the following situation, with the following test url:
"http://schedule.psu.ed u/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
Sep 2 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
3448
by: test | last post by:
Hi everyone, I'm creating a desktop Python application that requires web-based authentication for accessing additional application features. HTTP GET is really simple. HTTP POST is not (at least for me anyway) ;) I have tried a few different sources, but I cannot get HTTP POST to successfully log in. I can login using FireFox at
3
2399
by: bruce | last post by:
hi paul... in playing around with the test python app (see below) i've got a couple of basic questions. i can't seem to find the answers via google, and when i've looked in the libxml2dom stuff that i downloaded i didn't see answers either... for the list in the "for label in d.xpath" how can i find out the size of the list???? a simple/basic question, but it's driving me up a wall!!!
0
2384
by: bruce | last post by:
hi... it appears that i'm running into a possible problem with mechanize/browser/python rgarding the "select_form" method. i've tried the following and get the error listed: br.select_form(nr = 1) br.select_form(name="foo") br.select_form(name=foo) br.select_form(name="foo")
2
3398
by: sauce | last post by:
Hi, this a newbie question, forgive me! Ok so I have some code written using the libxml2dom package (because I want to parse html pages) and I would like to have this work on a web server. The web server (from Hostmonster) has libxml2 installed, and I put the libxml2dom package folder in my cgi-bin directory where I'm running the script. However, when I try to run the script, I get this error: Traceback (most recent call last): File...
3
2641
by: bruce | last post by:
Hi... got a short test app that i'm playing with. the goal is to get data off the page in question. basically, i should be able to get a list of "tr" nodes, and then to iterate/parse them. i'm missing something, as i think i can get a single node, but i can't figure out how to display the contents of the node.. nor how to get the list of the "tr" nodes....
1
2218
by: bruce | last post by:
Hi. Got a test web page, that basically has two "<html" tags in it. Examining the page via Firefox/Dom Inspector, I can create a test xpath query "/html/body/form" which gets the target form for the test. The issue comes when I examine the page's source html. It looks like: <html> <body> </body>
0
169
by: bruce | last post by:
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...
0
944
by: bruce | last post by:
hi... i can use an xpath query to create a node from an html/dom representation. however, if i have a node, is there a way to generate an xpath query from the node. in testing with firefox/dom inspector, i can use "ancestor::*", but i can't determine where/how to implement this using mechanize/libxml2dom thanks
0
818
by: John J Lee | last post by:
On Mon, 1 Sep 2008, bruce wrote: Just a general point: try lxml.etree instead? Friendlier API. John
0
9636
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10139
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10075
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8961
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7485
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3632
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2869
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.