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
chopper-0.6.0.linux-x86_64.tar.gz
(22.6 kB
view hashes)
Built Distribution
chopper-0.6.0-py3-none-any.whl
(16.4 kB
view hashes)
Close
Hashes for chopper-0.6.0.linux-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1d80edbdbe1775e678c548b548e47f3865f3c21db73d65113fd54e985570d301 |
|
MD5 | b853b838758be139f9d34493d0226ffd |
|
BLAKE2b-256 | 50b9f85a586995dedd16998408d08e07c6c5b6cb2c65cdebc5f7d248faf95240 |