views:

20

answers:

1

using lxml is it possible to find recursively for tag " f1 ", i tried findall method but it works only for immediate children.

I think I should go for BeautifulSoup for this !!!

+1  A: 

You can use XPath to search recursively:

>>> from lxml import etree
>>> q = etree.fromstring('<xml><hello>a</hello><x><hello>b</hello></x></xml>')
>>> q.findall('hello')     # Tag name, first level only.
[<Element hello at 414a7c8>]
>>> q.findall('.//hello')  # XPath, recursive.
[<Element hello at 414a7c8>, <Element hello at 414a818>]
Max Shawabkeh