why the conut( ) can not get the number?

Peter Otten __peter__ at web.de
Mon Dec 10 08:17:03 EST 2012


水静流深 wrote:

> i wnat to get the number of  a atrributes in a xpath,here is my code,why i
> can not get the number ? import urllib
> import lxml.html
> down="http://python-gtk-3-tutorial.readthedocs.org/en/latest/index.html"
> file=urllib.urlopen(down).read()
> root=lxml.html.document_fromstring(file)
> for order,node in enumerate(root.xpath('//li[@class="toctree-l1"]')):
>   print order,node.xpath('.//a[count(*)]')

This looks more like an xpath than a python problem. I'm no xpath expert -- 
and you don't describe the expected outcome -- maybe you want

print order, node.xpath("count(.//a)")




More information about the Python-list mailing list