Skip to content

Instantly share code, notes, and snippets.

@nealcaren
Created November 25, 2014 14:50
Show Gist options
  • Save nealcaren/1fa420e2396c3358cb69 to your computer and use it in GitHub Desktop.
Save nealcaren/1fa420e2396c3358cb69 to your computer and use it in GitHub Desktop.
# http://stackoverflow.com/questions/753052/strip-html-from-strings-in-python
from HTMLParser import HTMLParser
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()
test = ''' <p class="story-body-text story-content" data-para-count="232" data-total-count="5231" itemprop="articleBody" id="story-continues-6">Chief Belmar said the initial, hands-off tactics by the police were intended to allow protesters to stage peaceful demonstrations, but he said that the situation ultimately grew so unstable that it required a more forceful approach.</p><p class="story-body-text story-content" data-para-count="257" data-total-count="5488" itemprop="articleBody">But the Rev. Waltrina Middleton, who traveled here from Chicago to help maintain peace, blamed the police for aggression. “I think they’re going over the top,” she said. “A lot of what you see is a response to the aggressive nature of the police.”</p><p class="story-body-text story-content" data-para-count="245" data-total-count="5733" itemprop="articleBody">A variety of businesses in the Ferguson area, including nail shops, a Walgreens and a public storage facility, went up in flames. Firefighters, the police said, could not easily reach burning businesses because the conditions were too dangerous.</p><p class="story-body-text story-content" data-para-count="181" data-total-count="5914" itemprop="articleBody">Gunfire rang out frequently throughout the night — sometimes sounding like it came from an automatic weapon — forcing protesters and reporters along the strip to rush for cover.</p><figure id="2014-11-24-ferguson-map" class="interactive interactive-embedded limit-small layout-flex-medium"> '''
strip_tags(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment