Clean and normalize HTML.
Project description
Clean and normalize HTML. Preserve embeddings (e.g. Twitter, Instagram, etc)
Quick start
Installation
Install the library with pip:
pip install clear-html
Usage
Example usage with lxml:
from lxml.html import fromstring
from clear_html import clean_node, cleaned_node_to_html
html="""
<div style="color:blue" id="main_content">
Some text to be
<div>cleaned up!</div>
</div>
"""
node = fromstring(html)
cleaned_node = clean_node(node)
cleaned_html = cleaned_node_to_html(cleaned_node)
print(cleaned_html)
Example usage with Parsel:
from parsel import Selector
from clear_html import clean_node, cleaned_node_to_html
selector = Selector(text="""<html>
<body>
<h1>Hello!</h1>
<div style="color:blue" id="main_content">
Some text to be
<div>cleaned up!</div>
</div>
</body>
</html>""")
selector = selector.css("#main_content")
cleaned_node = clean_node(selector[0].root)
cleaned_html = cleaned_node_to_html(cleaned_node)
print(cleaned_html)
Both of the different approaches above would print the following:
<article>
<p>Some text to be</p>
<p>cleaned up!</p>
</article>
Other interesting functions:
cleaned_node_to_text: convert the cleaned node to plain text
formatted_text.clean_doc: low level method to control more aspects of the cleaning up
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
File details
Details for the file clear_html-0.5.0.tar.gz.
File metadata
- Download URL: clear_html-0.5.0.tar.gz
- Upload date:
- Size: 111.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26a98b6ac36468d461343ed8617c131dc1ad1cb52d2d0767df2041685e671151
|
|
| MD5 |
4627ca1619d319b75605a301c22be93a
|
|
| BLAKE2b-256 |
33569f0c437f695d5d0726797f596bdc276e3c1e3d4679b416ca306e562ed8e5
|
Provenance
The following attestation bundles were made for clear_html-0.5.0.tar.gz:
Publisher:
publish.yml on zytedata/clear-html
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clear_html-0.5.0.tar.gz -
Subject digest:
26a98b6ac36468d461343ed8617c131dc1ad1cb52d2d0767df2041685e671151 - Sigstore transparency entry: 636858042
- Sigstore integration time:
-
Permalink:
zytedata/clear-html@d634e109c2614171036b6c219a77608027ca156c -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/zytedata
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d634e109c2614171036b6c219a77608027ca156c -
Trigger Event:
push
-
Statement type:
File details
Details for the file clear_html-0.5.0-py3-none-any.whl.
File metadata
- Download URL: clear_html-0.5.0-py3-none-any.whl
- Upload date:
- Size: 24.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72b3f413dac50d3eaafd40b7ac2c9dac9fe133be97abf0a09d77d9690bc993f5
|
|
| MD5 |
1a5665016db8811b7aa2795b0bdc7bbd
|
|
| BLAKE2b-256 |
3996e5e6e5fe5cb59cf3b2ee811db4ae1df748ecba0926fa2b4aaaa1da3d93dc
|
Provenance
The following attestation bundles were made for clear_html-0.5.0-py3-none-any.whl:
Publisher:
publish.yml on zytedata/clear-html
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
clear_html-0.5.0-py3-none-any.whl -
Subject digest:
72b3f413dac50d3eaafd40b7ac2c9dac9fe133be97abf0a09d77d9690bc993f5 - Sigstore transparency entry: 636858044
- Sigstore integration time:
-
Permalink:
zytedata/clear-html@d634e109c2614171036b6c219a77608027ca156c -
Branch / Tag:
refs/tags/0.5.0 - Owner: https://github.com/zytedata
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@d634e109c2614171036b6c219a77608027ca156c -
Trigger Event:
push
-
Statement type: