[lxml-dev] Efficient way to search element attribs?

Stefan Behnel stefan_ml at behnel.de
Sat May 24 13:52:05 CEST 2008


Hi,

Viksit Gaur wrote:
> When building a tree, I add a particular attribute to each element (eg: 
> ID), and was wondering if there are any methods I could use to search 
> the tree for tags that have this attribute?
> 
> I looked at find(), findall() and the xpath functions - but they seem to 
> help only when you know the tag name itself.

You should read a bit on XPath, or at least on the ElementPath syntax.

http://effbot.org/zone/element-xpath.htm

The '*' wildcard allows you to search for any element tag. All iterators in
lxml.etree support it, BTW.

Stefan



More information about the lxml-dev mailing list