#!/usr/bin/env python3
from html.parser import HTMLParser
class HTMLPrint(HTMLParser):
def handle_starttag(self, tag, attrs):
print("start:", tag, attrs)
def handle_endtag(self, tag):
print("end :", tag)
def error(self, message):
print("ERROR:", message, self.getpos())
"""
The first string causes HTMLParser to just stop.
The second text raises an exception.
"""
texts = ['', '']
for text in texts:
print('text: ' + text)
HTMLPrint(strict=True).feed(text)
print('----------------')
HTMLPrint(strict=False).feed(text)
print('================')