How to use lxml to find an element by text?

前端 未结 2 921
北荒
北荒 2020-12-25 13:05

Assume we have the following html:


    
        TEXT A
        T         


        
2条回答
  •  执念已碎
    2020-12-25 13:11

    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)
    

提交回复
热议问题