# Parsing The `HTML` class parses a string of HTML and provides methods to [query](querying.md) the DOM for specific elements. ## \_\_init\_\_ Creates an `HTML` object from a `str` or `bytes`. ```python from minestrone import HTML html = HTML(""" The Dormouse's Story

The Dormouse's Story

""") ``` If closing tags are missing, then they will be added as needed to make the HTML valid. ```python from minestrone import HTML assert str(HTML("dormouse")) == "dormouse" ``` ## encoding The encoding of the HTML string is detected automatically, however it isn't always correct. An encoding can be passed along if necessary. ```python from minestrone import HTML html_bytes = b"

\xed\xe5\xec\xf9

" assert str(HTML(html_bytes)) == "

翴檛

" assert HTML(html_bytes).encoding == "big5" assert str(HTML(html_bytes), encoding="iso-8859-8") == "

םולש

" assert HTML(html_bytes).encoding == "iso-8859-8" ``` ## prettify Returns a prettified version of the HTML. ```python html = HTML(""" The Dormouse's Story

The Dormouse's Story

""") assert html.prettify() == """ The Dormouse's Story

The Dormouse's Story

""" ``` ## \_\_str\_\_ Returns the `HTML` object as a string. ```python from minestrone import HTML html = HTML(""" The Dormouse's Story

The Dormouse's Story

""") assert str(html) == """ The Dormouse's Story

The Dormouse's Story

""" ``` ```{note} Rendering the `HTML` into a string _will_ remove preceding spaces. ```