Created
December 16, 2010 17:57
-
-
Save mattd/743729 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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