Use the html5lib package components
masterThe html5lib package provides tools for parsing and serializing HTML according to the HTML5 specification. The core functionality is divided into several modules:
html5lib.html5parser: Used for parsing HTML content into a tree structure.html5lib.serializer: Used for converting tree structures back into HTML strings via theHTMLSerializerclass.html5lib.constants: Contains various constants used throughout the library.
For advanced manipulation of the parsed tree, you can use the following subpackages:
html5lib.filters: For filtering tree nodes.html5lib.treebuilders: For defining how the tree is constructed.html5lib.treewalkers: For traversing the tree.html5lib.treeadapters: For adapting different tree implementations to the library's interface.