How to get an attribute value using BeautifulSoup and Python?

前端 未结 3 1642
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-15 11:52

I\'m failing miserably to get an attribute value using BeautifulSoup and Python. Here is how the XML is structured:

...


    

        
3条回答
  •  遥遥无期
    2020-12-15 12:35

    Your "tag" can have multiple "stat" entries. Do you only have one "tag" entry?

    If so then first find the "tag", then loop through the "stat" entries that are contained within the "tag" entry. Something like:

    for stat in soup.find("tag").find_all("stat"):
        print(stat["pass"])
    

提交回复
热议问题