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

后端 未结 1 1772
走了就别回头了
走了就别回头了 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('xyz')
    for attr, value in page.find('foo').attrs:
        print attr, "=", value
    
    # Prints:
    # bar = asdf
    # blah = 123
    

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