Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何遍历 Beautiful Soup 元素的 HTML 属性?
就像,给定:
<foo bar="asdf" blah="123">xyz</foo>
我想要“bar”和“blah”。
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