trafilatura

Python & Command-line tool to gather text and metadata on the Web: Crawling, scraping, extraction, output as CSV, JSON, HTML, MD, TXT, XML

https://github.com/adbar/trafilatura

Science Score: 77.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 6 DOI reference(s) in README
  • Academic publication links
    Links to: zenodo.org
  • Committers with academic emails
    3 of 39 committers (7.7%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.9%) to scientific vocabulary

Keywords

article-extractor corpus-builder corpus-tools crawler html-to-markdown html2text llm news-aggregator news-crawler nlp rag readability rss-feed scraping tei text-cleaning text-extraction text-mining text-preprocessing web-scraping

Keywords from Contributors

webscraping opengraph metadata-extraction information-extraction date-parser datetime digital-forensics entity-extraction forensics-tools lemmatization
Last synced: 6 months ago · JSON representation ·

Repository

Python & Command-line tool to gather text and metadata on the Web: Crawling, scraping, extraction, output as CSV, JSON, HTML, MD, TXT, XML

Basic Info
Statistics
  • Stars: 4,627
  • Watchers: 33
  • Forks: 308
  • Open Issues: 85
  • Releases: 39
Topics
article-extractor corpus-builder corpus-tools crawler html-to-markdown html2text llm news-aggregator news-crawler nlp rag readability rss-feed scraping tei text-cleaning text-extraction text-mining text-preprocessing web-scraping
Created almost 7 years ago · Last pushed 7 months ago
Metadata Files
Readme Changelog Contributing Funding License Citation

README.md

Trafilatura: Discover and Extract Text Data on the Web


Trafilatura Logo


Python package Python versions Documentation Status Code Coverage Downloads Reference DOI: 10.18653/v1/2021.acl-demo.15


Demo as GIF image


Introduction

Trafilatura is a cutting-edge Python package and command-line tool designed to gather 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 perform web crawling, downloads, scraping, and extraction of main texts, metadata and comments. It aims at staying handy and modular: no database is required, the output can be converted to commonly used formats.

Going from HTML bulk to essential parts can alleviate many problems related to text quality, by focusing on the actual content, avoiding the noise caused by recurring elements like headers and footers and by making sense of the data and metadata with selected information. The extractor strikes a balance between limiting noise (precision) and including all valid parts (recall). It is robust and reasonably fast.

Trafilatura is widely used and integrated into thousands of projects by companies like HuggingFace, IBM, and Microsoft Research as well as institutions like the Allen Institute, Stanford, the Tokyo Institute of Technology, and the University of Munich.

Features

  • Advanced web crawling and text discovery:

    • Support for sitemaps (TXT, XML) and feeds (ATOM, JSON, RSS)
    • Smart crawling and URL management (filtering and deduplication)
  • Parallel processing of online and offline input:

    • Live URLs, efficient and polite processing of download queues
    • Previously downloaded HTML files and parsed HTML trees
  • Robust and configurable 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 formatting
    • Optional elements: comments, links, images, tables
  • Multiple output formats:

    • TXT and Markdown
    • CSV
    • JSON
    • HTML, XML and XML-TEI
  • Optional add-ons:

    • Language detection on extracted content
    • Speed optimizations
  • Actively maintained with support from the open-source community:

    • Regular updates, feature additions, and optimizations
    • Comprehensive documentation

Evaluation and alternatives

Trafilatura 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 information see the benchmark section and the evaluation readme to run the evaluation with the latest data and packages.

Other evaluations:

Usage and documentation

Getting started with Trafilatura is straightforward. For more information and detailed guides, visit Trafilatura's documentation:

Youtube playlist with video tutorials in several languages:

License

This package is distributed under the Apache 2.0 license.

Versions prior to v1.8.0 are under GPLv3+ license.

Contributing

Contributions of all kinds are welcome. Visit the Contributing page for more information. Bug reports can be filed on the dedicated issue page.

Many thanks to the contributors who extended the docs or submitted bug reports, features and bugfixes!

Context

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. Initially launched to create text databases for research purposes at the Berlin-Brandenburg Academy of Sciences (DWDS and ZDL units), this package continues to be maintained but its future depends on community support.

If you value this software or depend on it for your product, consider sponsoring it and contributing to its codebase. Your support on GitHub or ko-fi.com will help maintain and enhance this popular package.

Trafilatura is an Italian word for wire drawing symbolizing the refinement and conversion process. It is also the way shapes of pasta are formed.

Author

Reach out via ia the software repository or the contact page for inquiries, collaborations, or feedback. See also social networks for the latest updates.

Citing Trafilatura

Trafilatura is widely used in the academic domain, chiefly for data acquisition. Here is how to cite it:

Reference DOI: 10.18653/v1/2021.acl-demo.15 Zenodo archive DOI: 10.5281/zenodo.3460969

shell @inproceedings{barbaresi-2021-trafilatura, title = {{Trafilatura: A Web Scraping Library and Command-Line Tool for Text Discovery and Extraction}}, 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 ecosystem

Jointly developed plugins and additional packages also contribute to the field of web data extraction and analysis:

Software ecosystem

Corresponding posts can be found on Bits of Language.

Impressive, you have reached the end of the page: Thank you for your interest!

Owner

  • Name: Adrien Barbaresi
  • Login: adbar
  • Kind: user
  • Location: Berlin
  • Company: Berlin-Brg. Academy of Sciences (BBAW)

Research scientist – natural language processing, web scraping and text analytics. Mostly with Python.

Citation (CITATION.cff)

authors:
  - family-names: Barbaresi
    given-names: Adrien
    orcid: https://orcid.org/0000-0002-8079-8694
cff-version: 1.2.0
identifiers:
  - description: "This is the collection of archived snapshots of all versions of Trafilatura"
    type: doi
    value: 10.5281/zenodo.3460969
message: "If you use this software, please cite both the article from preferred-citation and the software itself."
preferred-citation:
  authors:
    - family-names: Barbaresi
      given-names: Adrien
  title: "Trafilatura: A Web Scraping Library and Command-Line Tool for Text Discovery and Extraction"
  type: article
  year: 2021
repository: https://github.com/adbar/trafilatura
repository-code: https://github.com/adbar/trafilatura
title: Trafilatura
type: software
url: https://trafilatura.readthedocs.io/

GitHub Events

Total
  • Create event: 20
  • Release event: 1
  • Issues event: 61
  • Watch event: 921
  • Delete event: 20
  • Issue comment event: 156
  • Push event: 77
  • Pull request review comment event: 27
  • Pull request review event: 25
  • Pull request event: 67
  • Fork event: 56
Last Year
  • Create event: 20
  • Release event: 1
  • Issues event: 61
  • Watch event: 921
  • Delete event: 20
  • Issue comment event: 156
  • Push event: 77
  • Pull request review comment event: 27
  • Pull request review event: 25
  • Pull request event: 67
  • Fork event: 56

Committers

Last synced: about 2 years ago

All Time
  • Total Commits: 1,395
  • Total Committers: 39
  • Avg Commits per committer: 35.769
  • Development Distribution Score (DDS): 0.102
Past Year
  • Commits: 103
  • Committers: 16
  • Avg Commits per committer: 6.438
  • Development Distribution Score (DDS): 0.252
Top Committers
Name Email Commits
Adrien Barbaresi b****i@b****e 1,253
Felipe Hertzer f****r@g****m 59
Felipe Hertzer f****r 16
Vincent Barbaresi v****i@g****m 11
Luise K l****r@g****m 8
LukasBBAW 6****W 5
Phong Nguyen p****t@g****m 4
Ido Shamun i****1@g****m 3
André Mácola a****a@g****m 3
Ellie Lockhart 6****t 2
Edward Krueger e****r@g****m 2
Tony Yang t****a@g****m 2
Korben k****n@k****o 1
Kunal Sareen k****n@a****u 1
Luise Koehler l****r@b****e 1
Martin Müller m****l@m****t 1
Aleks Bunin s****b 1
Hergen Lehmann 3****m 1
sourcery-ai[bot] 5****] 1
feltcat 5****t 1
dsgibbons 8****s 1
dependabot[bot] 4****] 1
deedy5 6****5 1
Mark Mayo m****k@t****z 1
Mathieu Dhondt l****o@g****m 1
Michael Rienstra m****a@g****m 1
Phong Nguyen p****n@P****l 1
Raphael Geronimi r****i@g****m 1
Sean Madden m****a@o****u 1
Sourcery AI b****t@s****i 1
and 9 more...

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 259
  • Total pull requests: 420
  • Average time to close issues: 5 months
  • Average time to close pull requests: 9 days
  • Total issue authors: 141
  • Total pull request authors: 53
  • Average comments per issue: 2.35
  • Average comments per pull request: 1.9
  • Merged pull requests: 315
  • Bot issues: 0
  • Bot pull requests: 50
Past Year
  • Issues: 51
  • Pull requests: 81
  • Average time to close issues: 16 days
  • Average time to close pull requests: 3 days
  • Issue authors: 36
  • Pull request authors: 23
  • Average comments per issue: 0.71
  • Average comments per pull request: 1.86
  • Merged pull requests: 58
  • Bot issues: 0
  • Bot pull requests: 3
Top Authors
Issue Authors
  • adbar (64)
  • alroythalus (12)
  • fortyfourforty (9)
  • andremacola (7)
  • Honesty-of-the-Cavernous-Tissue (5)
  • zirkelc (4)
  • felipehertzer (4)
  • naktinis (3)
  • pieterhartel (3)
  • DesBw (3)
  • krstp (3)
  • edkrueger (3)
  • majcl (2)
  • lord-alfred (2)
  • ibestvina (2)
Pull Request Authors
  • adbar (267)
  • dependabot[bot] (51)
  • felipehertzer (19)
  • unsleepy22 (13)
  • knit-bee (10)
  • vbarbaresi (6)
  • andremacola (4)
  • gremid (4)
  • zirkelc (3)
  • idoshamun (3)
  • UVMvmfee (2)
  • ra312 (2)
  • steineggerroland (2)
  • naktinis (2)
  • co-odw (2)
Top Labels
Issue Labels
enhancement (55) bug (47) question (37) feedback (20) documentation (15) maintenance (15) wontfix (4) duplicate (3) up for grabs (3) good first issue (2) evaluation (2) dependencies (1)
Pull Request Labels
dependencies (51) feedback (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 1,365,602 last-month
  • Total docker downloads: 9,653
  • Total dependent packages: 71
  • Total dependent repositories: 63
  • Total versions: 50
  • Total maintainers: 1
pypi.org: trafilatura

Python & Command-line tool to gather text and metadata on the Web: Crawling, scraping, extraction, output as CSV, JSON, HTML, MD, TXT, XML.

  • Versions: 50
  • Dependent Packages: 71
  • Dependent Repositories: 63
  • Downloads: 1,365,602 Last month
  • Docker Downloads: 9,653
Rankings
Dependent packages count: 0.2%
Downloads: 0.7%
Stargazers count: 1.5%
Average: 1.7%
Dependent repos count: 1.9%
Docker downloads count: 2.4%
Forks count: 3.8%
Maintainers (1)
Last synced: 6 months ago

Dependencies

docs/requirements.txt pypi
  • docutils >=0.18.1
  • pydata-sphinx-theme >=0.9.0
  • sphinx >=5.0.2
  • trafilatura *
setup.py pypi
  • certifi *
  • charset_normalizer *
  • courlan *
  • htmldate *
  • justext *
  • lxml *
  • urllib3 *
tests/eval-requirements.txt pypi
  • beautifulsoup4 ==4.11.1 test
  • boilerpy3 ==1.0.6 test
  • goose3 ==3.1.11 test
  • html-text ==0.5.2 test
  • html2text ==2020.1.16 test
  • inscriptis ==2.2.0 test
  • justext ==3.0.0 test
  • news-please ==1.5.22 test
  • newspaper3k ==0.2.8 test
  • readabilipy ==0.2.0 test
  • readability-lxml ==0.8.1 test
  • trafilatura ==1.2.2 test
.github/workflows/codeql.yml actions
  • actions/checkout v3 composite
  • github/codeql-action/analyze v2 composite
  • github/codeql-action/autobuild v2 composite
  • github/codeql-action/init v2 composite
.github/workflows/tests.yml actions
  • actions/cache v2 composite
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • codecov/codecov-action v3 composite