trafilatura
https://github.com/adbar/trafilatura
https://trafilatura.readthedocs.io/
https://github.com/adbar/trafilatura/issues
Trafilatura is a Python package and command-line tool which seamlessly downloads, parses, and scrapes web page data: it can extract metadata, main body text and comments while preserving parts of the text formatting and page structure. The output can be converted to different formats.
Distinguishing between a whole page and the page’s essential parts can help to alleviate many quality problems related to web text processing, by dealing with the noise caused by recurring elements (headers and footers, ads, links/blogroll, etc.).
The extractor aims to be precise enough in order not to miss texts or to discard valid documents. In addition, it must be robust, but also reasonably fast. With these objectives in mind, Trafilatura is designed to run in production on millions of web documents. It is based on lxml as well as readability and jusText as fallback.
Download and conversion utilities included
URLs, HTML files or parsed HTML trees as input
Main text and/or comments
Structural elements preserved: paragraphs, titles, lists, quotes, code, line breaks, in-line text formatting
Extraction of metadata (title, author, date, site name, categories and tags)
Plain text (minimal formatting)
CSV (with metadata, tab-separated values)
JSON (with metadata)
XML (for metadata and structure) and TEI-XML
Support for sitemaps and ATOM/RSS feeds
Efficient and polite processing of URL queues
Blacklisting
Optional language detection on extracted content
The extraction focuses on the main content: usually the part displayed centrally, without left or right bars, header or footer, but including potential titles and (optionally) comments. These tasks are also known as web scraping, boilerplate removal, DOM-based content extraction, main content identification, or web page cleaning.
For reproducible results see the evaluation page and the evaluation script.
Most efficient open-source library in ScrapingHub’s article extraction benchmark as well as in another independant evaluation on the same data.
Best overall tool according to Gaël Lejeune & Adrien Barbaresi, Bien choisir son outil d’extraction de contenu à partir du Web (2020, PDF, French).
Primary method is with Python package manager: pip install --upgrade trafilatura.
pip install --upgrade trafilatura
For more details please read the installation documentation.
With Python or on the command-line.
In a nutshell, with Python:
>>> import trafilatura >>> downloaded = trafilatura.fetch_url('https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/') >>> trafilatura.extract(downloaded) # outputs main content and comments as plain text ...
On the command-line:
$ trafilatura -u "https://github.blog/2019-03-29-leader-spotlight-erin-spiceland/" # outputs main content and comments as plain text ...
For more information please refer to usage documentation and tutorials.
Trafilatura is distributed under the GNU General Public License v3.0. If you wish to redistribute this library but feel bounded by the license conditions please try interacting at arms length, multi-licensing with compatible licenses, or contacting me.
See also GPL and free software licensing: What’s in it for business?
Trafilatura: Italian word for wire drawing.
Corresponding posts on Bits of Language (blog).
[-] Duplicate detection at sentence, paragraph and document level using a least recently used (LRU) cache
[-] URL lists and document management
[-] Configuration and extraction parameters
[-] Graphical user interface
[ ] Interaction with web archives (notably WARC format)
[ ] Integration of natural language processing tools
Contributions are welcome!
Feel free to file issues on the dedicated page. Thanks to the contributors who submitted features and bugfixes!
This effort is part of methods to derive information from web documents in order to build text databases for research (chiefly linguistic analysis and natural language processing). Extracting and pre-processing web texts to the exacting standards of scientific research presents a substantial challenge for those who conduct such research. Web corpus construction involves numerous design decisions, and this software package can help facilitate text data collection and enhance corpus quality.
Barbaresi, A. “Generic Web Content Extraction with Open-Source Software”, Proceedings of KONVENS 2019, Kaleidoscope Abstracts, 2019.
Barbaresi, A. “Efficient construction of metadata-enhanced web corpora”, Proceedings of the 10th Web as Corpus Workshop (WAC-X), 2016.
You can contact me via my contact page or GitHub.
Index
Module Index
Search Page