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.
pip install html-textVerified import paths — ran on the pinned version, not inferred.
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.
For flatter output, call `html_text.extract_text(html_string, guess_layout=False)`.
Always clean manually before using lower-level extraction functions, e.g., `cleaned_tree = html_text.cleaner.clean_html(tree)` or `cleaned_sel = html_text.cleaned_selector(html_content)`.
Refer to the `lxml` installation guide (often linked from its PyPI page or documentation) for specific system dependencies required before `pip install lxml` or `pip install html-text`.
Use `import html_text` instead of `import html-text` in your Python code.
If you intended to use the `html-text` library, import it as `import html_text`. If you intended to use the `html2text` library, install it with `pip install html2text` and then `import html2text`.
Ensure you are calling the correct function with the proper casing: `html_text.extract_text(your_html_content)`.