473,769 Members | 5,757 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Re: python/xpath question..

On Wed, 2008-09-03 at 13:36 -0700, bruce wrote:
morning....

i apologize up front as this is really more of an xpath question..

in my python, i'm using the xpath function to iterate/parse some html. i can
do something like

s=d.xpath("//tr/td/text()")
count=len(s)

and get the number of nodes that have text

i can then do something like
s=d.xpath("//tr/td")
count2=len(s)

and get the number of total nodes...
by subtracting, i can get the number of nodes, without text.. is there an
easier way??!!
count2-count

ie, if i have something like
<tr>
<td></td>
<td>foo</td>
</tr>

is there a way to get the count that there is a single "td" node with
text()=""

thanks
--
http://mail.python.org/mailman/listinfo/python-list
Well, you could just do the test (and the count!) in the xpath
expression:

count( //tr/td[ text() != "" ] )

It sounds like you're not familiar with xpath? I would recommend the
O'Reilly XSLT book, it has an excellent introduction to xpath in chapter
3.
--
John Krukoff <jk******@ltgc. com>
Land Title Guarantee Company

Sep 3 '08 #1
0 1063

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

Similar topics

3
6935
by: Nelson Minar | last post by:
Could someone help me get started using XPath or XQuery in Python? I'm overwhelmed by all the various options and am lacking guidance on what the simplest way to go is. What library do I need to enable three line Python programs to extract data with XPath expressions? I have this problem a lot with Python and XML. Even with Uche's excellent yearly roundups I have a hard time finding how to do fancy things with XML in Python. I think it's...
3
2410
by: Thierry Lam | last post by:
Let's say I have the following xml tag: <para role="success">1</para> I can't figure out what kind of python xml.dom codes I should invoke to read the data 1? Any help please? Thanks Thierry
5
2079
by: And80 | last post by:
Hi, I would like to use xpath modules in python2.4.... In my local machine I am running python2.3.5 and on the server I run python2.4. I have seen that while on my computer i am able to import xml.xpath, on the server the module seems to not exist. Is it still part of the standard library? if not, what should I use? Thank you in advance, Andrea Fiore
0
382
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!!!
3
2489
by: bruce | last post by:
for guys with python/xpath expertise.. i'm playing with xpath.. and i'm trying to solve an issue... i have the following kind of situation where i'm trying to get certain data. i have a bunch of tr/td... i can create an xpath, that gets me all of the tr.. i only want to get the sibling tr up until i hit a 'tr' that has a 'th' anybody have an idea as to
1
1737
by: bruce | last post by:
Hi Paul... Thanks for the reply. Came to the same conclusion a few minutes before I saw your email. Another question: tr=d.xpath(foo) gets me an array of 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>
1
1940
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...
2
1378
by: bruce | last post by:
morning.... i apologize up front as this is really more of an xpath question.. in my python, i'm using the xpath function to iterate/parse some html. i can do something like s=d.xpath("//tr/td/text()") count=len(s)
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10210
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
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...
0
8869
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
7406
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
6668
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3955
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
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.