fast python port of arc90's readability tool, updated to match latest readability.js!
See the codeGiven an HTML document, extract and clean up the main body text and title.
This is a Python port of a Ruby port of arc90's Readability project.
It's easy using pip, just run:
$ pip install readability-lxml
As an alternative, you may also use conda to install, just run:
$ conda install -c conda-forge readability-lxml
>>> import requests
>>> from readability import Document
>>> response = requests.get('http://example.com')
>>> doc = Document(response.content)
>>> print(doc.title())
Example Domain
>>> print(doc.summary())
<html><body><div><body id="readabilityBody">
<div>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may
use this domain in examples without prior coordination or asking for permission.</p>
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</div></body></html>
The command-line interface accepts a local HTML file or a URL:
python -m readability -u https://example.com
Run the real-page extraction benchmark with the default minimum F1 of 0.95:
make benchmark
BENCHMARK_MIN_SCORE=0.97 make benchmark
In a reproducible comparison of ten extraction engines on 181 saved pages,
Readability 0.9 ranks second overall with F1 0.975 and first on the 51 pages
outside Mozilla Readability's own fixture corpus with F1 0.975. Mozilla
Readability ranks first overall (F1 0.986), but 130 of the 181 fixtures come
from its test suite. The quality evaluation
includes the corpus, methodology, complete results, failures, and per-page
measurements.
Document.summary() removes common active content while extracting an article,
but readability-lxml is not a security boundary or a general-purpose HTML
sanitizer. Applications that render untrusted output must apply a dedicated
allowlist sanitizer and an appropriate Content Security Policy.
lxml 6 support, and updated packaging metadata for Markdown documentation and current cssselect releases.python -m readability execution for local files and URLs.get_clean_html() before another API call has initialized the document.<div> elements into paragraphs.display: none, visibility: hidden, HTML hidden, and <noscript> fallback content before scoring.sidebar.<main> or <article> containers during unlikely-candidate filtering.srcdoc content.jcharum/lxml-readability.This code is under the Apache License 2.0 license.
2,241 followers · starred Mar 2026
4,022 followers · starred Aug 2023
161 followers · starred Dec 2020
505 followers · starred Jun 2020
fast python port of arc90's readability tool, updated to match latest readability.js!
See the codeGiven an HTML document, extract and clean up the main body text and title.
This is a Python port of a Ruby port of arc90's Readability project.
It's easy using pip, just run:
$ pip install readability-lxml
As an alternative, you may also use conda to install, just run:
$ conda install -c conda-forge readability-lxml
>>> import requests
>>> from readability import Document
>>> response = requests.get('http://example.com')
>>> doc = Document(response.content)
>>> print(doc.title())
Example Domain
>>> print(doc.summary())
<html><body><div><body id="readabilityBody">
<div>
<h1>Example Domain</h1>
<p>This domain is established to be used for illustrative examples in documents. You may
use this domain in examples without prior coordination or asking for permission.</p>
<p><a href="http://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</div></body></html>
The command-line interface accepts a local HTML file or a URL:
python -m readability -u https://example.com
Run the real-page extraction benchmark with the default minimum F1 of 0.95:
make benchmark
BENCHMARK_MIN_SCORE=0.97 make benchmark
In a reproducible comparison of ten extraction engines on 181 saved pages,
Readability 0.9 ranks second overall with F1 0.975 and first on the 51 pages
outside Mozilla Readability's own fixture corpus with F1 0.975. Mozilla
Readability ranks first overall (F1 0.986), but 130 of the 181 fixtures come
from its test suite. The quality evaluation
includes the corpus, methodology, complete results, failures, and per-page
measurements.
Document.summary() removes common active content while extracting an article,
but readability-lxml is not a security boundary or a general-purpose HTML
sanitizer. Applications that render untrusted output must apply a dedicated
allowlist sanitizer and an appropriate Content Security Policy.
lxml 6 support, and updated packaging metadata for Markdown documentation and current cssselect releases.python -m readability execution for local files and URLs.get_clean_html() before another API call has initialized the document.<div> elements into paragraphs.display: none, visibility: hidden, HTML hidden, and <noscript> fallback content before scoring.sidebar.<main> or <article> containers during unlikely-candidate filtering.srcdoc content.jcharum/lxml-readability.This code is under the Apache License 2.0 license.
2,241 followers · starred Mar 2026
4,022 followers · starred Aug 2023
161 followers · starred Dec 2020
505 followers · starred Jun 2020