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 >= 2.6, <= 3.4
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.4.0.tar.gz
(8.8 kB
view details)
File details
Details for the file chopper-0.4.0.tar.gz
.
File metadata
- Download URL: chopper-0.4.0.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2028f6fb27f9629401d4a5c9a87c0be31cf3645fecc1824372b34005999d6a58 |
|
MD5 | 8891748ee430edd5c20e77448bf83450 |
|
BLAKE2b-256 | 1eca884fea5471415a2a8efb22abeb73291d3f44b22e908306ece831d7f82bb2 |