Skip to main content

Fast and robust extraction of original and updated publication dates from URLs and web pages.

Project description

Htmldate: Find the Publication Date of Web Pages

Python package Python versions Documentation Status Code Coverage Downloads JOSS article reference DOI: 10.21105/joss.02439


Htmldate Logo

Find original and updated publication dates of any web page. It is often not possible to do it using just the URL or the server response.

On the command-line or with Python, all the steps needed from web page download to HTML parsing, scraping, and text analysis are included.

The package is used in production on millions of documents and integrated into thousands of projects.

In a nutshell


Demo as GIF image

With Python

>>> from htmldate import find_date
>>> find_date('http://blog.python.org/2016/12/python-360-is-now-available.html')
'2016-12-23'

On the command-line

$ htmldate -u http://blog.python.org/2016/12/python-360-is-now-available.html
'2016-12-23'

Features

  • Flexible input: URLs, HTML files, or HTML trees can be used as input (including batch processing).
  • Customizable output: Any date format (defaults to ISO 8601 YMD).
  • Detection of both original and updated dates.
  • Multilingual.
  • Compatible with all recent versions of Python.

How it works

Htmldate operates by sifting through HTML markup and if necessary text elements. It features the following heuristics:

  1. Markup in header: Common patterns are used to identify relevant elements (e.g. link and meta elements) including Open Graph protocol attributes.
  2. HTML code: The whole document is searched for structural markers like abbr or time elements and a series of attributes (e.g. postmetadata).
  3. Bare HTML content: Heuristics are run on text and markup:
    • In fast mode the HTML page is cleaned and precise patterns are targeted.
    • In extensive mode all potential dates are collected and a disambiguation algorithm determines the best one.

Finally, the output is validated and converted to the chosen format.

Performance

1000 web pages containing identifiable dates (as of 2023-11-13 on Python 3.10)

Python Package Precision Recall Accuracy F-Score Time
articleDateExtractor 0.20 0.803 0.734 0.622 0.767 5x
date_guesser 2.1.4 0.781 0.600 0.514 0.679 18x
goose3 3.1.17 0.869 0.532 0.493 0.660 15x
htmldate[all] 1.6.0 (fast) 0.883 0.924 0.823 0.903 1x
htmldate[all] 1.6.0 (extensive) 0.870 0.993 0.865 0.928 1.7x
newspaper3k 0.2.8 0.769 0.667 0.556 0.715 15x
news-please 1.5.35 0.801 0.768 0.645 0.784 34x

For the complete results and explanations see evaluation page.

Installation

Htmldate is tested on Linux, macOS and Windows systems, it is compatible with Python 3.8 upwards. It can notably be installed with pip (pip3 where applicable) from the PyPI package repository:

  • pip install htmldate
  • (optionally) pip install htmldate[speed]

The last version to support Python 3.6 and 3.7 is htmldate==1.8.1.

Documentation

For more details on installation, Python & CLI usage, please refer to the documentation: htmldate.readthedocs.io

License

This package is distributed under the Apache 2.0 license.

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

Context and contributions

Initially launched to create text databases for research purposes at the Berlin-Brandenburg Academy of Sciences (DWDS and ZDL units), this project continues to be maintained but its future development 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 will help maintain and enhance this package. Visit the Contributing page for more information.

Reach out via the software repository or the contact page for inquiries, collaborations, or feedback.

JOSS article reference DOI: 10.21105/joss.02439 Zenodo archive DOI: 10.5281/zenodo.3459599

@article{barbaresi-2020-htmldate,
  title = {{htmldate: A Python package to extract publication dates from web pages}},
  author = "Barbaresi, Adrien",
  journal = "Journal of Open Source Software",
  volume = 5,
  number = 51,
  pages = 2439,
  url = {https://doi.org/10.21105/joss.02439},
  publisher = {The Open Journal},
  year = 2020,
}

Acknowledgements

Kudos to the following software libraries:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htmldate-1.9.4.tar.gz (44.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

htmldate-1.9.4-py3-none-any.whl (31.6 kB view details)

Uploaded Python 3

File details

Details for the file htmldate-1.9.4.tar.gz.

File metadata

  • Download URL: htmldate-1.9.4.tar.gz
  • Upload date:
  • Size: 44.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for htmldate-1.9.4.tar.gz
Algorithm Hash digest
SHA256 1129063e02dd0354b74264de71e950c0c3fcee191178321418ccad2074cc8ed0
MD5 46e059f9ec0a5f6a0532c50f6bd0b058
BLAKE2b-256 9d10ead9dabc999f353c3aa5d0dc0835b1e355215a5ecb489a7f4ef2ddad5e33

See more details on using hashes here.

File details

Details for the file htmldate-1.9.4-py3-none-any.whl.

File metadata

  • Download URL: htmldate-1.9.4-py3-none-any.whl
  • Upload date:
  • Size: 31.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.13.1

File hashes

Hashes for htmldate-1.9.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1b94bcc4e08232a5b692159903acf95548b6a7492dddca5bb123d89d6325921c
MD5 13e19cb657f4b4ff02965cbe323f3a89
BLAKE2b-256 a1bdadfcdaaad5805c0c5156aeefd64c1e868c05e9c1cd6fd21751f168cd88c7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page