如何获取HTML标记的所有属性?
listinp = soup('input')
for input in listinp:
# get all attr on this tag in dict
答案 0 :(得分:2)
使用attrs
:
for tag in listinp:
print dict(tag.attrs)
答案 1 :(得分:0)
在BeautifulSoup中使用prettify()
import urllib2, BeautifulSoup
opener = urllib2.build_opener()
host = "http://google.com"
site = opener.open(host)
html = site.read()
soup = BeautifulSoup(html)
print soup.pretiffy()