Skip to content

Instantly share code, notes, and snippets.

@seekshreyas
Created November 10, 2013 11:40
Show Gist options
  • Select an option

  • Save seekshreyas/7397197 to your computer and use it in GitHub Desktop.

Select an option

Save seekshreyas/7397197 to your computer and use it in GitHub Desktop.
Strip HTML tags from a string in Python
# reference: http://stackoverflow.com/questions/753052/strip-html-from-strings-in-python
# To strip html tags
class MLStripper(HTMLParser):
def __init__(self):
self.reset()
self.fed = []
def handle_data(self, d):
self.fed.append(d)
def get_data(self):
return ''.join(self.fed)
def strip_tags(html):
s = MLStripper()
s.feed(html)
return s.get_data()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment