finding elements by attribute with lxml

前端 未结 2 826
轮回少年
轮回少年 2021-01-30 12:40

I need to parse a xml file to extract some data. I only need some elements with certain attributes, here\'s an example of document:


    

        
2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-01-30 13:32

    Just for reference, you can achieve the same result with findall:

    root = etree.fromstring("""
    
        
            
    some text
    some text
    some text
    """) articles = root.find("articles") article_list = articles.findall("article[@type='news']/content") for a in article_list: print a.text

提交回复
热议问题