Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
python html.parser
class MyHTMLParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.isTags = False
self.tags = None
def handle_starttag(self, tag, attrs):
if tag == 'p':
if containsAttr(attrs, 'class', 'tags'):
self.isTags = True
elif isThisX(tag, attrs):
self.isX = True
elif isThisX(tag, attrs):
self.isY
else:
self.isAdd = False
def handle_endtag(self, tag):
if tag == 'p':
self.isTags = False
elif wasX(tag):
self.isX = False
elif wasY(tag):
self.isY = False
def handle_data(self, data):
if self.isTags:
print('text: ', data)
elif self.isX:
print('X: ', data);
elif self.isY:
print('Y', data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.