Skip to content

Instantly share code, notes, and snippets.

@mattd
Created December 16, 2010 17:57
Show Gist options
  • Save mattd/743729 to your computer and use it in GitHub Desktop.
Save mattd/743729 to your computer and use it in GitHub Desktop.
def strip_tags(tags, html):
soup = BeautifulSoup(html)
for tag in soup.findAll(True):
if tag.name in tags:
s = ""
for c in tag.contents:
if type(c) != NavigableString:
c = strip_tags(tags, unicode(c))
s += unicode(c)
tag.replaceWith(s)
return soup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment