skillfed

html-text

Extract text from HTML

html-text v0.7.1 1.4M downloads/30d#3,908 on PyPI19
Permissive license MIT AGING released

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-text

uv

uv add html-text

poetry

poetry add html-text

Installing 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

Development Status :: 4 - BetaIntended Audience :: DevelopersNatural Language :: EnglishProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9

Tags

extract text from htmlhtml to plain textremove html tagsclean html contenttext extraction from web pageshtml parsing and text extractionconvert html to text
web-scrapingtext-extractionnlp-preprocessing

More HTML packages