views:

76

answers:

2

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

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

Use attrs:

for tag in listinp:
    print dict(tag.attrs)
Mark Byers
A: 

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()
Gunslinger_