How do I iterate over the HTML attributes of a Beautiful Soup element?

后端 未结 1 1766
走了就别回头了
走了就别回头了 2020-12-09 09:45

How do I iterate over the HTML attributes of a Beautiful Soup element?

Like, given:

xyz
相关标签:
1条回答
  • 2020-12-09 10:06
    from BeautifulSoup import BeautifulSoup
    page = BeautifulSoup('<foo bar="asdf" blah="123">xyz</foo>')
    for attr, value in page.find('foo').attrs:
        print attr, "=", value
    
    # Prints:
    # bar = asdf
    # blah = 123
    
    0 讨论(0)
提交回复
热议问题