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
Usage
from tree_extractor import TreeExtractor
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 = TreeExtractor().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
tree_extractor-0.1.7.tar.gz
(5.5 kB
view details)
File details
Details for the file tree_extractor-0.1.7.tar.gz
.
File metadata
- Download URL: tree_extractor-0.1.7.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b870c0b07a66f7f9abd4b9e019f0fcff0b013f740fe386ef1eb61b02aa695bb6 |
|
MD5 | cee0be21c99de6f9ed3284a81aef036e |
|
BLAKE2b-256 | fa86a41015a7cef832ba976867b967145adbf662b3eaea9bef4df8e59c1a82f4 |