Skip to content

Instantly share code, notes, and snippets.

@goddoe
Created January 20, 2022 03:24
Show Gist options
  • Select an option

  • Save goddoe/1c016cd5057e7e634560653b03f89844 to your computer and use it in GitHub Desktop.

Select an option

Save goddoe/1c016cd5057e7e634560653b03f89844 to your computer and use it in GitHub Desktop.
html parser example
from html.parser import HTMLParser
class StripQuery(HTMLParser):
def __init__(self):
super(StripQuery, self).__init__()
self.query = ""
def handle_starttag(self, tag, attrs):
pass
def handle_endtag(self, tag):
pass
def handle_data(self, data):
self.query += data
def strip_query(q):
f = StripQuery()
f.feed(q)
return f.query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment