Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何获取HTML标记的所有属性?_Python_Beautifulsoup - Fatal编程技术网

Python 如何获取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()

如何获取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()
host = "http://google.com"
site = opener.open(host)
html = site.read()
soup = BeautifulSoup(html)
print soup.pretiffy()