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