Inscriptis is a Python-based HTML to text conversion library, command line client, and Web service (v2.7.1). It specializes in providing high-quality, layout-aware text representations of HTML content, including support for nested tables and a subset of CSS, and offers optional annotated output. The library is actively maintained with regular releases addressing new Python versions and feature enhancements.
pip install inscriptisVerified import paths — ran on the pinned version, not inferred.
Convert HTML from a URL to plain text, preserving layout and structure. The example fetches content from 'https://www.informationscience.ch' and prints its text representation.
If using `XmlAnnotationProcessor`, be aware of the new `<content>` root element. The name can be overwritten by providing the `root_element` parameter to the processor call.
Upgrade your Python environment to version 3.10 or newer (up to <3.15) to maintain compatibility with `inscriptis`.
For long-running services processing many complex HTML documents, monitor memory usage and consider restarting processes periodically or optimizing the HTML input where possible. This is a characteristic of `lxml` rather than a direct `inscriptis` bug.
Install the library using pip: `pip install inscriptis`
Remove the `.decode()` call if the input is already a string, or ensure the input is a `bytes` object before calling `.decode()`. For example, if reading from a network or file, ensure you obtain `bytes` before decoding: `html_content_bytes.decode('utf-8')`.Convert the `str` object to a `bytes` object using the `.encode()` method with the appropriate encoding, typically UTF-8: `some_string_variable.encode('utf-8')`.When using `XmlAnnotationProcessor`, be aware that the output will include a `<content>` root element by default. If you need a different root element, specify it using the `root_element` parameter: `XmlAnnotationProcessor(root_element='my_root')`.