← All notes

Python html.parser: a simple HTML and XHTML parser

Answer: The user should subclass HTMLParser and override its methods to implement the desired behavior.

How the parser is used

This module defines a class HTMLParser that can handle HTML and XHTML.

An HTMLParser instance is fed HTML data and calls handler methods when markup is recognized.

Create a parser instance able to parse invalid markup.

This parser does not check that end tags match start tags.

Character references

The default value for argument convert_charrefs is now True.

If convert_charrefs is true, all character references are converted, except the ones in special cases listed in the docs.

handle_data() might be called more than once if convert_charrefs is false and you feed incomplete chunks.

Override handle_starttag and the other handler methods in your subclass.

See also

Claims

Sources

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, html.parser — Simple HTML and XHTML parser; CPython, html.parser documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation. Text was condensed and changed from the originals.

License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Python Software Foundation, html.parser — Simple HTML and XHTML parser; CPython, html.parser documentation (source). PSF-2.0 (https://docs.python.org/3/license.html). Copyright Python Software Foundation.

Cite this

Permanent ID: iil:note:f53zh36p

iinventedlight. 2026. "Python html.parser: a simple HTML and XHTML parser." iinventedlight Library, iil:note:f53zh36p, version of 2026-11-24. https://iinventedlight.com/library/notes/python-html-parser/. License: CC-BY-4.0.

@misc{iil_note_f53zh36p,
  author = {{iinventedlight}},
  title = {{Python html.parser: a simple HTML and XHTML parser}},
  howpublished = {iinventedlight Library},
  year = {2026},
  date = {2026-11-24},
  url = {https://iinventedlight.com/library/notes/python-html-parser/},
  note = {Permanent ID iil:note:f53zh36p. License: CC-BY-4.0.},
}

Markdown

Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).

Extra files beside this note

These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.

All artifact files (JSON index)

For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-html-parser.md.