python - How do I insert an attribute using BeautifulSoup? -
how insert attribute using beautifulsoup?
for example, insert border="1" tag attribute.
edit:
i've answered own question (for particular class of table, even):
intopic = urllib2.urlopen("file:///c:/test/test.html") content = beautifulsoup(intopic)
tlist = content.findall('table', "mytableclass") tbl in tlist: tbl['border'] = "1" print tbl.attrs
how about:
intopic = urllib2.urlopen('http://stackoverflow.com/questions/4951331/how-do-i-insert-an-attribute-using-beautifulsoup') content = beautifulsoup.beautifulsoup(intopic) tlist = content.findall('table') tbl in tlist: tbl.attrs.append(('border', 1))
do not forget try lxml.html
, it's fast , parse well.
Comments
Post a Comment