Next / Previous / Contents / Shipman's homepage

9.6. Element.findall(): Find all matching sub-elements

This method returns a list of descendants of the element that match a pattern described by the path argument.

E.findall(path[, namespaces=N])

The way that the path argument describes the desired set of nodes works the same ways as the path argument described in Section 9.5, “Element.find(): Find a matching sub-element”.

For example, if an article element named root has zero or more children named section, this call would set sectionList to a list containing Element instances representing those children.

    sectionList = root.findall('section')

The optional namespaces keyword argument allows you to specify a namespace map. If supplied, this namespace map is used to interpret namespace prefixes in the path; see Section 9.5, “Element.find(): Find a matching sub-element” for details.

Warning

The namespaces keyword argument is available only since release 2.3.0 of lxml.etree.