开发者

How can I get all the attributes of a HTML tag?

开发者 https://www.devze.com 2023-01-12 20:27 出处:网络
How can I get all the att开发者_开发知识库ributes of a HTML tag? listinp = soup(\'input\') for input in listinp:

How can I get all the att开发者_开发知识库ributes of a HTML tag?

listinp = soup('input')
for input in listinp:
    # get all attr on this tag in dict


Use attrs:

for tag in listinp:
    print dict(tag.attrs)


use pretiffy() in BeautifulSoup

import urllib2, BeautifulSoup
opener = urllib2.build_opener()
host = "http://google.com"
site = opener.open(host)
html = site.read()
soup = BeautifulSoup(html)
print soup.pretiffy()
0

精彩评论

暂无评论...
验证码 换一张
取 消