A HTML5 parser.
Project description
Dompa
A work-in-progress HTML5 document parser. It takes an input of an HTML string, parses it into a node tree, and provides an API that aims to be Web APIs compatible to modify said node tree.
Install
pip install dompa
Usage
The most basic usage looks like this:
from dompa import Dompa
dom = Dompa("<div>Hello, World</div>")
# Get the tree of nodes
nodes = dom.nodes()
# Get the HTML string
html = dom.html()
DOM manipulation
You can run queries on the node tree to get or manipulate node(s).
find
You can find nodes with the find method which takes a Callable that gets Node passed to it and that has to return
a boolean true or false, like so:
from dompa import Dompa
dom = Dompa("<h1>Site Title</h1><ul><li>...</li><li>...</li></ul>")
list_items = dom.find(lambda n: n.name == "li")
update
You can update nodes with the update method which takes a Callable, like so:
from dompa import Dompa
from dompa.nodes import Node, TextNode
dom = Dompa("<h1>Site Title</h1><ul><li>...</li><li>...</li></ul>")
def update_title(item: Node) -> None:
if item.name == "h1":
item.children = [TextNode(value="New Title")]
dom.update(update_title)
remove
Not implemented yet.
add_before
Not implemented yet.
add_after
Not implemented yet.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dompa-0.3.0-py3-none-any.whl.
File metadata
- Download URL: dompa-0.3.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c23dd68230bfcffde0ccf79bc0b07235f4e6c579e2cf1131c04f2d8e90a712e
|
|
| MD5 |
dca549d85c7e0f0bdc0398ea6569219d
|
|
| BLAKE2b-256 |
6ff5de44273f613a74f1ca646ba027216c2bf93ec498112850ea91fa061227a1
|