html.parser.HTMLParser()
html.parser.HTMLParser() is a Python function in the HTML Module category. A push parser for HTML that calls handler methods for tags and data. The syntax is html.parser.HTMLParser(*, convert_charrefs=True). Returns: HTMLParser instance. A typical example: from html.parser import HTMLParser
class MyParser(HTMLParser):
def handle_starttag(self, tag, attrs):
print(f"Tag: {tag}")
p = MyParser()
p.feed("
Hello
"). A close sibling is
html.escape(), which converts special HTML characters (&, <, >, ", ') to HTML-safe entities. A close sibling is
html.unescape(), which converts HTML entities back to characters. More about this category: HTML escaping — escape, unescape, HTMLParser. Related HTML Module entries:
html.escape(),
html.unescape(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try html.parser.HTMLParser() immediately in the
Python playground, look up unfamiliar terms in the
glossary, or return to the
Python Reference homepage.