html-text

0.7.1 · active · verified Sat Apr 11

html-text is a Python library designed to extract clean, readable plain text from HTML content. It goes beyond simple text extraction by removing invisible non-text content like inline styles, JavaScript, and comments. The library intelligently normalizes whitespace and can optionally add newlines after block-level elements (e.g., headers, paragraphs) to produce text that more closely resembles browser rendering, making it suitable for text classification or further natural language processing. The current version is 0.7.1, and it maintains an active development status.

Warnings

Install

Imports

Quickstart

Demonstrates the basic usage of `html_text.extract_text` to convert an HTML string into plain text, including an example of disabling layout guessing for a flatter output.

import html_text

html_content = '<h1>Hello</h1><p>This is a <b>paragraph</b> with <span>inline</span> text.</p>'
plain_text = html_text.extract_text(html_content)
print(plain_text)

# To get text without layout-driven newlines (e.g., after h1)
plain_text_flat = html_text.extract_text(html_content, guess_layout=False)
print(plain_text_flat)

view raw JSON →