--- id: html5lib version: "1.1" license: MIT License license_treatment: permissive maintenance: active --- # html5lib — HTML parser based on the WHATWG HTML specification License: permissive · Maintenance: active · Popularity: top 1,000 on PyPI ## Install pip install html5lib uv add html5lib poetry add html5lib ## Description html5lib ======== .. image:: https://travis-ci.org/html5lib/html5lib-python.svg?branch=master :target: https://travis-ci.org/html5lib/html5lib-python html5lib is a pure-python library for parsing HTML. It is designed to conform to the WHATWG HTML specification, as is implemented by all major web browsers. Usage ----- Simple usage follows this pattern: .. code-block:: python import html5lib with open("mydocument.html", "rb") as f: document = html5lib.parse(f) or: .. code-block:: python import html5lib document = html5lib.parse("
Hello World!") By default, the ``document`` will be an ``xml.etree`` element instance. Whenever possible, html5lib chooses the accelerated ``ElementTree`` implementation (i.e. ``xml.etree.cElementTree`` on Python 2.x). Two other tree types are supported: ``xml.dom.minidom`` and ``lxml.etree``. To use an alternative format, specify the name of a treebuilder: .. code-block:: python import html5lib with open("mydocument.html", "rb") as f: lxml_etree_document = html5lib.parse(f, treebuilder="lxml") When using with ``urllib2`` (Python 2), the charset from HTTP should be pass into html5lib as follows: ..... ## AI interpretation — verify before relying html5lib is a pure-Python HTML parser that conforms to the WHATWG HTML specification, parsing HTML documents into tree structures compatible with xml.etree, xml.dom.minidom, or lxml. Verdict: html5lib is a stable, actively maintained HTML parser with minimal dependencies and no known vulnerabilities. The long gap since the last release (2020) is offset by recent repository activity. It's suitable for production use where WHATWG-compliant HTML parsing is needed, though users should verify ongoing maintenance aligns with their support expectations. [View on SkillFed](https://skillfed.io/packages/html5lib) · [View on PyPI](https://pypi.org/project/html5lib/)