Package: trafilatura
IntroductionTrafilatura is a cutting-edgePython package and command-line tooldesigned togather text on the Web and simplify the process of turning raw HTML into structured, meaningful data. It includes all necessary discovery and text processing components to performweb crawling, downloads, scraping, and extractionof main texts, metadata and comments. It aims at stayinghandy and modular: no database is required, the output can be converted to multiple commonly used formats.Smart navigation and going from HTML bulk to essential parts can alleviate many problems related to text quality, byfocusing on the actual content,avoiding the noisecaused by recurring elements (headers, footers etc.),making sense of the datawith selected information. The extractor is designed to berobust and reasonably fast, it runs in production on millions of documents.The tool’s versatility makes it useful for a wide range of applications leveraging web content for knowledge discovery such asquantitative and data-driven approaches. Trafilatura is used in the academic domain and beyond (e.g. in NLP, SEO, business analytics).FeaturesAdvanced web crawling and text discovery:Focused crawling adhering to politeness rulesSupport for sitemaps (TXT, XML) and feeds (ATOM, JSON, RSS)Smart navigation and URL management (blacklists, filtering and deduplication)Parallel processing of online and offline input:Live URLs, efficient and polite processing of download queuesPreviously downloaded HTML files and parsed HTML treesRobust and customizable extraction of key elements:Main text (common patterns and generic algorithms like jusText and readability)Metadata (title, author, date, site name, categories and tags)Formatting and structure: paragraphs, titles, lists, quotes, code, line breaks, in-line text formattingOptional elements: comments, links, images, tablesExtensive configuration optionsMultiple output formats:Text (minimal formatting or Markdown)CSV (with metadata, tab-separated values)JSON (with metadata)XML (with metadata, text formatting and page structure) andTEI-XMLAdd-ons:Language detection on extracted contentGraphical user interface (GUI)Speed optimizationsActively maintained with support from the open-source community:Regular updates, feature additions, and optimizationsComprehensive documentationEvaluation and alternativesTrafilatura consistently outperforms other open-source libraries in text extraction benchmarks, showcasing its efficiency and accuracy in extracting web content. The extractor tries to strike a balance between limiting noise and including all valid parts.For more detailed results see thebenchmark. The results can be reproduced, see theevaluation readmefor instructions.750 documents, 2236 text & 2250 boilerplate segments (2022-05-18), Python 3.8Python PackagePrecisionRecallAccuracyF-ScoreDiff.html_text 0.5.20.5290.9580.5540.6822.2xinscriptis 2.2.0 (html to txt)0.5340.9590.5630.6863.5xnewspaper3k 0.2.80.8950.5930.7620.71312xjustext 3.0.0 (custom)0.8650.6500.7750.7425.2xboilerpy3 1.0.6 (article mode)0.8140.7440.7870.7774.1xbaseline (text markup)0.7570.8270.7810.7901xgoose3 3.1.90.9340.6900.8210.79322xreadability-lxml 0.8.10.8910.7290.8200.8015.8xnews-please 1.5.220.8980.7340.8260.80861xreadabilipy 0.2.00.8770.8700.8740.874248xtrafilatura 1.2.2 (standard)0.9140.9040.9100.9097.1xOther evaluations:Most efficient open-source library inScrapingHub’sarticle extraction benchmarkBest overall tool according toBien choisir son outil d’extraction de contenu à partir du Web(Lejeune & Barbaresi 2020)Best single tool by ROUGE-LSum Mean F1 Page Scores inAn Empirical Comparison of Web Content Extraction Algorithms(Bevendorff et al. 2023)Usage and documentationGetting started with Trafilaturais straightforward. For more information and detailed guides, visitTrafilatura’s documentation:InstallationUsage:On the command-line,With Python,With RCore Python functionsInteractive Python Notebook:Trafilatura OverviewTutorials and use casesText embedding for vector searchCustom web corpusWord frequency listFor video tutorials see this Youtube playlist:Web scraping tutorials and how-tosLicenseTrafilaturais distributed under theGNU General Public License v3.0. This license promotes collaboration in software development and ensures that Trafilatura’s code remains publicly accessible.If you wish to redistribute this library but are concerned about the license conditions, consider interactingat arms length, combining withcompatible licenses, orcontacting the authorfor more options.For insights into GPL and free software licensing with emphasis on a business context, seeGPL and Free Software Licensing: What’s in it for Business?ContributingContributions of all kinds are welcome. Visit theContributing pagefor more information. Bug reports can be filed on thededicated issue page.Many thanks to thecontributorswho extended the docs or submitted bug reports, features and bugfixes!ContextDeveloped with practical applications of academic research in mind, this software is part of a broader effort to derive information from web documents. Extracting and pre-processing web texts to the exacting standards of scientific research presents a substantial challenge. Web corpus construction involves numerous design decisions, this software package simplifies text data collection and enhances corpus quality. It is currently used to buildtext databases for linguistic research.Trafilaturais an Italian word forwire drawingsymbolizing the industrial-grade extraction, refinement and conversion process.AuthorReach out via thecontact pagefor inquiries, collaborations, or feedback. See alsoTwitter/Xfor the latest updates.This work started as a PhD project at the crossroads of linguistics and NLP, this expertise has been instrumental in shaping Trafilatura over the years. It has first been released under its current form in 2019, its development is referenced in the following publications:Barbaresi, A.Trafilatura: A Web Scraping Library and Command-Line Tool for Text Discovery and Extraction, Proceedings of ACL/IJCNLP 2021: System Demonstrations, 2021, p. 122-131.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 the10th Web as Corpus Workshop (WAC-X), 2016.Citing TrafilaturaTrafilatura is used in the academic domain, chiefly for data acquisition in corpus linguistics, natural language processing, and computational social science. Here is how to cite it:@inproceedings{barbaresi-2021-trafilatura,title={{Trafilatura:AWebScrapingLibraryandCommand-LineToolforTextDiscoveryandExtraction}},author="Barbaresi, Adrien",booktitle="Proceedings of the Joint Conference of the 59th Annual Meeting of the Association for Computational Linguistics and the 11th International Joint Conference on Natural Language Processing: System Demonstrations",pages="122--131",publisher="Association for Computational Linguistics",url="https://aclanthology.org/2021.acl-demo.15",year=2021,}Software ecosystemThis software is part of a larger ecosystem. It is employed in a variety of academic and development projects, demonstrating its versatility and effectiveness. Case studies and publications are listed on theUsed By documentation page.Jointly developed plugins and additional packages also contribute to the field of web data extraction and analysis:Corresponding posts can be found onBits of Language. The blog covers a range of topics from technical how-tos, updates on new features, to discussions on text mining challenges and solutions.Impressive, you have reached the end of the page: Thank you for your interest!