Created
January 20, 2022 03:24
-
-
Save goddoe/1c016cd5057e7e634560653b03f89844 to your computer and use it in GitHub Desktop.
html parser example
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
| 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