Assume we have the following html:
TEXT A T
Another way that looks more straightforward to me:
results = [] root = lxml.hmtl.fromstring(the_html_above) for tag in root.iter(): if "TEXT A" in tag.text results.append(tag)