Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: python/xpath question..

Reply
Thread Tools

Re: python/xpath question..

 
 
Stefan Behnel
Guest
Posts: n/a
 
      09-04-2008
Hi,

you should really read about XPath. There are also newsgroups specifically for
this topic, please use them.


bruce wrote:
> 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


That is a wrong assumption. It will give you the number of text nodes, not the
number of elements. They may or may not be the same.


> 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??!!


Yes, learn to use XPath, e.g.

//tr/td[not string()]

Stefan
 
Reply With Quote
 
 
 
 
Stefan Behnel
Guest
Posts: n/a
 
      09-04-2008
Stefan Behnel wrote:
> Yes, learn to use XPath, e.g.
>
> //tr/td[not string()]


Oh, well...

//tr/td[not(string())]

as I said, wrong news group.

Try something like "gmane.text.xml.xpath.general", for example.

Stefan
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments