Lib to extract html elements by preserving ancestors and cleaning CSS
Project description
Chopper is a tool to extract elements from HTML by preserving ancestors and CSS rules.
Compatible with Python >= 3.8
Installation
pip install chopper
Full documentation
Quick start
from chopper.extractor import Extractor
HTML = """
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="header"></div>
<div id="main">
<div class="iwantthis">
HELLO WORLD
<a href="/nope">Do not want</a>
</div>
</div>
<div id="footer"></div>
</body>
</html>
"""
CSS = """
div { border: 1px solid black; }
div#main { color: blue; }
div.iwantthis { background-color: red; }
a { color: green; }
div#footer { border-top: 2px solid red; }
"""
extractor = Extractor.keep('//div[@class="iwantthis"]').discard('//a')
html, css = extractor.extract(HTML, CSS)
The result is :
>>> html
"""
<html>
<body>
<div id="main">
<div class="iwantthis">
HELLO WORLD
</div>
</div>
</body>
</html>"""
>>> css
"""
div{border:1px solid black;}
div#main{color:blue;}
div.iwantthis{background-color:red;}
"""
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 Distribution
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
chopper-0.6.0-py3-none-any.whl
(16.4 kB
view details)
File details
Details for the file chopper-0.6.0.linux-x86_64.tar.gz.
File metadata
- Download URL: chopper-0.6.0.linux-x86_64.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d80edbdbe1775e678c548b548e47f3865f3c21db73d65113fd54e985570d301
|
|
| MD5 |
b853b838758be139f9d34493d0226ffd
|
|
| BLAKE2b-256 |
50b9f85a586995dedd16998408d08e07c6c5b6cb2c65cdebc5f7d248faf95240
|
File details
Details for the file chopper-0.6.0-py3-none-any.whl.
File metadata
- Download URL: chopper-0.6.0-py3-none-any.whl
- Upload date:
- Size: 16.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
662f87c1922c5661c4560c7b770fb7e59fcc846fe29b0911f865dc80ef664e6e
|
|
| MD5 |
f12cbf817031f7e13b669c743d542d89
|
|
| BLAKE2b-256 |
9b9db361aa78acb0ea02e456db57e9988a064b527ecd9c266a51ee1ef2f462fc
|