Lib to extract html elements by preserving ancestors and cleaning CSS
Project description
Extracts html contents by preserving ancestors and clean CSS
Compatible with Python >= 2.6, <= 3.4
Installation
pip install chopper
Usage
from chopper 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.2.1.tar.gz
(7.4 kB
view details)
File details
Details for the file chopper-0.2.1.tar.gz
.
File metadata
- Download URL: chopper-0.2.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b3b6188cedc4bfc5c9a3b99e2d2981956f4de0aedf852d1103ec525a635d10f9 |
|
MD5 | 1ade7f5eff6451837220b24df9b82bd5 |
|
BLAKE2b-256 | 3c017f3be4fe517f72aca51c3d703d8b433314e97ad0856320c2a910eab13e17 |