clean-html-for-llm


Nameclean-html-for-llm JSON
Version 1.3.2 PyPI version JSON
download
home_pagehttps://github.com/shubhamofbce/clean-html-for-llm.git
SummaryA library for cleaning HTML content by removing specified tags and attributes.
upload_time2024-04-10 12:24:54
maintainerNone
docs_urlNone
authorShubham Raj
requires_python>=3.7
licenseMIT
keywords html cleaning html cleaning for llm html denoise for llm html denoising for llm html cleaning for language model html denoise for language model html denoising for language model html cleaning for nlp html denoise for nlp html denoising for nlp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # clean_html_for_llm

This library provides a method to clean HTML content by removing specified tags and attributes while keeping specified attributes. It is particularly useful for preprocessing HTML data to remove noisy tags, making it easier for language models (LLMs) to understand the HTML and generate accurate responses.
This is helpful if you are querying LLMs with your HTML data.
![PyPI Version](https://img.shields.io/pypi/v/clean-html-for-llm)
![License](https://img.shields.io/badge/License-MIT-blue.svg)



## Installation

You can install the `clean_html_for_llm` library using pip:

```bash
pip install clean-html-for-llm
```

## Usage

```python
from clean_html_for_llm import clean_html

html_content = '<div id="main" style="color:red">Hello <script>alert("World")</script></div>'
cleaned_html = clean_html(html_content, tags_to_remove=['script'], attributes_to_keep=['id'])
print(cleaned_html)
# Output: '<div id="main">Hello </div>'
```

The `clean_html` function takes the following arguments:

- `html_to_clean` (str): The HTML content to clean.
- `tags_to_remove` (List[str]): List of tags to remove from the HTML content. Default is `['style', 'svg', 'script']`.
- `attributes_to_keep` (List[str]): List of attributes to keep in the HTML tags. Default is `['id', 'href']`.

You can customize the tags and attributes to remove or keep based on your requirements.

## Examples

### Example 1:

```python
html_content = '<div id="content" class="main">This is a <span style="font-size: 18px;">paragraph</span>.</div>'
cleaned_html = clean_html(html_content)
print(cleaned_html)
# Output: '<div id="content">This is a <span>paragraph</span>.</div>'
```

### Example 2:

```python
html_content = '<p class="content">Click <a href="https://example.com">here</a> for more information.</p>'
cleaned_html = clean_html(html_content, tags_to_remove=['a'], attributes_to_keep=['class'])
print(cleaned_html)
# Output: '<p class="content">Click </p>'
```

## License

This library is released under the MIT License. See [LICENSE](LICENSE) for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/shubhamofbce/clean-html-for-llm.git",
    "name": "clean-html-for-llm",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": null,
    "keywords": "html cleaning, html cleaning for llm, html denoise for llm, html denoising for llm, html cleaning for language model, html denoise for language model, html denoising for language model, html cleaning for nlp, html denoise for nlp, html denoising for nlp",
    "author": "Shubham Raj",
    "author_email": "sraj13169@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/f0/ef/bdaccf53409f54dae633ca584ce420d4f8868745d17e2d534192c0615fe2/clean_html_for_llm-1.3.2.tar.gz",
    "platform": null,
    "description": "# clean_html_for_llm\n\nThis library provides a method to clean HTML content by removing specified tags and attributes while keeping specified attributes. It is particularly useful for preprocessing HTML data to remove noisy tags, making it easier for language models (LLMs) to understand the HTML and generate accurate responses.\nThis is helpful if you are querying LLMs with your HTML data.\n![PyPI Version](https://img.shields.io/pypi/v/clean-html-for-llm)\n![License](https://img.shields.io/badge/License-MIT-blue.svg)\n\n\n\n## Installation\n\nYou can install the `clean_html_for_llm` library using pip:\n\n```bash\npip install clean-html-for-llm\n```\n\n## Usage\n\n```python\nfrom clean_html_for_llm import clean_html\n\nhtml_content = '<div id=\"main\" style=\"color:red\">Hello <script>alert(\"World\")</script></div>'\ncleaned_html = clean_html(html_content, tags_to_remove=['script'], attributes_to_keep=['id'])\nprint(cleaned_html)\n# Output: '<div id=\"main\">Hello </div>'\n```\n\nThe `clean_html` function takes the following arguments:\n\n- `html_to_clean` (str): The HTML content to clean.\n- `tags_to_remove` (List[str]): List of tags to remove from the HTML content. Default is `['style', 'svg', 'script']`.\n- `attributes_to_keep` (List[str]): List of attributes to keep in the HTML tags. Default is `['id', 'href']`.\n\nYou can customize the tags and attributes to remove or keep based on your requirements.\n\n## Examples\n\n### Example 1:\n\n```python\nhtml_content = '<div id=\"content\" class=\"main\">This is a <span style=\"font-size: 18px;\">paragraph</span>.</div>'\ncleaned_html = clean_html(html_content)\nprint(cleaned_html)\n# Output: '<div id=\"content\">This is a <span>paragraph</span>.</div>'\n```\n\n### Example 2:\n\n```python\nhtml_content = '<p class=\"content\">Click <a href=\"https://example.com\">here</a> for more information.</p>'\ncleaned_html = clean_html(html_content, tags_to_remove=['a'], attributes_to_keep=['class'])\nprint(cleaned_html)\n# Output: '<p class=\"content\">Click </p>'\n```\n\n## License\n\nThis library is released under the MIT License. See [LICENSE](LICENSE) for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A library for cleaning HTML content by removing specified tags and attributes.",
    "version": "1.3.2",
    "project_urls": {
        "Homepage": "https://github.com/shubhamofbce/clean-html-for-llm.git"
    },
    "split_keywords": [
        "html cleaning",
        " html cleaning for llm",
        " html denoise for llm",
        " html denoising for llm",
        " html cleaning for language model",
        " html denoise for language model",
        " html denoising for language model",
        " html cleaning for nlp",
        " html denoise for nlp",
        " html denoising for nlp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f90f32dab024ae329c19da55a69defecfbd6e658ef00ed6ea440f8aa1e8991eb",
                "md5": "e12a002f63f24c7b0430c0b16e537c30",
                "sha256": "0d33c726627be03b63bcc9880ef9f7cab9863969443de31fe4d26d84e7733545"
            },
            "downloads": -1,
            "filename": "clean_html_for_llm-1.3.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e12a002f63f24c7b0430c0b16e537c30",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 4014,
            "upload_time": "2024-04-10T12:24:53",
            "upload_time_iso_8601": "2024-04-10T12:24:53.094491Z",
            "url": "https://files.pythonhosted.org/packages/f9/0f/32dab024ae329c19da55a69defecfbd6e658ef00ed6ea440f8aa1e8991eb/clean_html_for_llm-1.3.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f0efbdaccf53409f54dae633ca584ce420d4f8868745d17e2d534192c0615fe2",
                "md5": "ef3064246c004f8e99bec6036a82e247",
                "sha256": "d39f1fe6761ff84f1917ced1c04985aa2411100f8ea3169475d55c78024971ae"
            },
            "downloads": -1,
            "filename": "clean_html_for_llm-1.3.2.tar.gz",
            "has_sig": false,
            "md5_digest": "ef3064246c004f8e99bec6036a82e247",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 3339,
            "upload_time": "2024-04-10T12:24:54",
            "upload_time_iso_8601": "2024-04-10T12:24:54.772542Z",
            "url": "https://files.pythonhosted.org/packages/f0/ef/bdaccf53409f54dae633ca584ce420d4f8868745d17e2d534192c0615fe2/clean_html_for_llm-1.3.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-10 12:24:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "shubhamofbce",
    "github_project": "clean-html-for-llm",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "clean-html-for-llm"
}
        
Elapsed time: 0.26551s