Markup Processing Modules
html.parser
Subclass HTMLParser to handle start tags, end tags and text through callbacks. It accepts many imperfect documents but does not build a browser DOM or validate matching tags. Do not treat parsing alone as HTML sanitization.
Formal Syntax & Structure
python syntaxpython
import html.parserReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from html.parser import HTMLParserclass Links(HTMLParser): def handle_starttag(self, tag, attrs): if tag == "a": print(dict(attrs).get("href"))Links().feed('<a href="/help">Help</a>')