How to remove all attributes of the specific elements througout the document. I\'m trying something like this:
from bs4 import UnicodeDammit
from lxml import
This is one possible way, assuming that you want to remove all attributes of certain element, say table
:
for table in root.xpath('//table[@*]'):
table.attrib.clear()
The code above loop through all table
that contains any attribute, then call clear()
method of the elemet's attrib
property, since the property is simply a python dictionary.