from BeautifulSoup import BeautifulSoup def _remove_attrs(soup): tag_list = soup.findAll(lambda tag: len(tag.attrs) > 0) for t in tag_list: for attr, val in t.attrs: del t[attr] return soup def example(): doc = '
junk