Python: BeautifulSoup - get an attribute value based on the name attribute

后端 未结 7 1786
抹茶落季
抹茶落季 2020-11-27 10:38

I want to print an attribute value based on its name, take for example


I want to do something

相关标签:
7条回答
  • 2020-11-27 11:33

    theharshest's answer is the best solution, but FYI the problem you were encountering has to do with the fact that a Tag object in Beautiful Soup acts like a Python dictionary. If you access tag['name'] on a tag that doesn't have a 'name' attribute, you'll get a KeyError.

    0 讨论(0)
提交回复
热议问题