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

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -