html-text
Extract text from HTML
What it is and what it does
html-text extracts readable text from HTML by removing invisible content (styles, scripts, comments) and normalizing whitespace in a way that mimics how a browser renders the page. Unlike simple XPath or Beautiful Soup text extraction, it adds intelligent spacing around inline elements and can insert newlines after headers and paragraphs to preserve document structure in the output.
The package provides multiple entry points: a high-level extract_text() function for raw HTML strings, lower-level etree_to_text() for pre-parsed lxml trees, and integration with parsel.Selector for targeted extraction from specific elements. It's designed for both display purposes and machine learning feature extraction, where clean, normalized text is needed as input to classification pipelines.
Use it for:
- Extract readable text from web pages for search indexing or content aggregation
- Prepare HTML content as features for text classification or NLP models
- Convert web scraping results to plain text for downstream text processing
- Remove boilerplate (styles, scripts) while preserving document structure via newlines
- Build text-only versions of web content for accessibility or archival
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Extracts plain text from HTML while filtering out styles, scripts, comments, and normalizing whitespace intelligently to match browser rendering.
Yes, if you need to extract clean text from HTML with structure preservation. Low install friction, permissive license, no known vulnerabilities, and stable API make it a safe choice. Maintenance is aging but the repository remains active; suitable for production use in text extraction pipelines.
Install
html-text on PyPI
pip
pip install html-textuv
uv add html-textpoetry
poetry add html-textInstalling html-text
Before you install
Low friction: pure Python wheel with only lxml and lxml-html-clean as runtime dependencies. Last release 312 days ago; repository is active and not archived, though maintenance status is aging.
License in practice
MIT license is permissive; you can use, modify, and distribute this package freely in commercial and private projects with minimal restrictions.
Quickstart
pip install html-text
import html_text
text = html_text.extract_text('<p>Hello</p><p>world</p>')
print(text)
Requires lxml, which has compiled C dependencies; installation may need a C compiler or pre-built wheels for your platform.
Verify before relying
- Whether parsel is an optional dependency or required for selector_to_text functionality
- Performance characteristics on large HTML documents or batch processing scenarios
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — lxml, lxml-html-clean |
| Maintenance | aging — 312 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,433,260/month — #3,908 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: html_text-0.7.1-py3-none-any.whl
Tags
More HTML packages
MarkupSafe provides a text object that escapes…
permissive · top 100 on PyPI
Jinja2Jinja2 is a templating engine that renders…
permissive · top 100 on PyPI
beautifulsoup4Beautiful Soup parses HTML and XML documents…
permissive · top 100 on PyPI
lxmllxml provides Python bindings to libxml2 and…
permissive · top 1,000 on PyPI
docutilsDocutils converts plaintext documentation in…
unclear · top 1,000 on PyPI
MarkdownConverts Markdown text to HTML using a Python…
permissive · top 1,000 on PyPI
jusTextjusText removes boilerplate content…
permissive · top 5,000 on PyPI
paragraphsProvides a single function that joins…
permissive · top 15,000 on PyPI
w3libw3lib provides utility functions for common web…
permissive · top 5,000 on PyPI
parselParsel extracts data from HTML, JSON, and XML…
permissive · top 5,000 on PyPI
procesProces provides text preprocessing functions…
permissive · top 15,000 on PyPI
html-sanitizerSanitizes HTML fragments by enforcing an…
permissive · top 5,000 on PyPI
boilerpy3Extracts main article text and content from…
permissive · top 15,000 on PyPI
pynlinerConverts CSS stylesheets to inline styles in…
permissive · top 15,000 on PyPI
css-inlineInlines CSS from style and link tags directly…
permissive · top 5,000 on PyPI
antiwordWraps LibreOffice's text conversion to convert…
permissive · top 15,000 on PyPI