Skip to main content

Clean and normalize HTML.

Project description

PyPI Version Supported Python Versions Build Status Coverage report

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clear_html-0.5.0.tar.gz (111.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clear_html-0.5.0-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

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

Hashes for clear_html-0.5.0.tar.gz
Algorithm Hash digest
SHA256 26a98b6ac36468d461343ed8617c131dc1ad1cb52d2d0767df2041685e671151
MD5 4627ca1619d319b75605a301c22be93a
BLAKE2b-256 33569f0c437f695d5d0726797f596bdc276e3c1e3d4679b416ca306e562ed8e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for clear_html-0.5.0.tar.gz:

Publisher: publish.yml on zytedata/clear-html

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for clear_html-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72b3f413dac50d3eaafd40b7ac2c9dac9fe133be97abf0a09d77d9690bc993f5
MD5 1a5665016db8811b7aa2795b0bdc7bbd
BLAKE2b-256 3996e5e6e5fe5cb59cf3b2ee811db4ae1df748ecba0926fa2b4aaaa1da3d93dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for clear_html-0.5.0-py3-none-any.whl:

Publisher: publish.yml on zytedata/clear-html

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page