Re: python/xpath question..

Discussion in 'Python' started by Stefan Behnel, Sep 4, 2008.

  1. 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
    Stefan Behnel, Sep 4, 2008
    #1
    1. Advertising

  2. 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
    Stefan Behnel, Sep 4, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    1,950
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,364
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    504
  4. goog
    Replies:
    0
    Views:
    490
  5. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    1,605
    Richard Tobin
    Nov 13, 2004
Loading...

Share This Page