Skip to main content

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

Project description

Python package Python versions Documentation Status Code Coverage Downloads

Code:

https://github.com/adbar/htmldate

Documentation:

https://htmldate.readthedocs.io

Issue tracker:

https://github.com/adbar/htmldate/issues


Find original and updated publication dates of any web page. From the command-line or within Python, all the steps needed from web page download to HTML parsing, scraping, and text analysis are included.

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'
>>> find_date('https://netzpolitik.org/2016/die-cider-connection-abmahnungen-gegen-nutzer-von-creative-commons-bildern/', original_date=True)
'2016-06-23'

On the command-line:

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

Features

  • Compatible with all recent versions of Python (see above)

  • Multilingual, robust and efficient (used in production on millions of documents)

  • URLs, HTML files, or HTML trees are given as input (includes batch processing)

  • Output as string in any date format (defaults to ISO 8601 YMD)

  • Detection of both original and updated dates

htmldate finds original and updated publication dates of web pages using heuristics on HTML code and linguistic patterns. It provides following ways to date a HTML document:

  1. Markup in header: Common patterns are used to identify relevant elements (e.g. link and meta elements) including Open Graph protocol attributes and a large number of CMS idiosyncrasies

  2. HTML code: The whole document is then searched for structural markers: abbr and time elements as well as a series of attributes (e.g. postmetadata)

  3. Bare HTML content: A series of heuristics is 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

Performance

500 web pages containing identifiable dates (as of 2021-09-24)

Python Package

Precision

Recall

Accuracy

F-Score

Time

articleDateExtractor 0.20

0.769

0.691

0.572

0.728

3.3x

date_guesser 2.1.4

0.738

0.544

0.456

0.626

20x

goose3 3.1.9

0.821

0.453

0.412

0.584

8.2x

htmldate[all] 0.9.1 (fast)

0.839

0.906

0.772

0.871

1x

htmldate[all] 0.9.1 (extensive)

0.825

0.990

0.818

0.900

1.7x

newspaper3k 0.2.8

0.729

0.630

0.510

0.675

8.4x

news-please 1.5.21

0.769

0.691

0.572

0.728

30x

For complete results and explanations see the evaluation page.

Installation

This Python package is tested on Linux, macOS and Windows systems, it is compatible with Python 3.6 upwards. It is available on the package repository PyPI and can notably be installed with pip (pip3 where applicable): pip install htmldate and optionally pip install htmldate[speed].

Documentation

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

License

htmldate 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?

Author

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. There are web pages for which neither the URL nor the server response provide a reliable way to find out when a document was published or modified. For more information:

JOSS article Zenodo archive
@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,
}

You can contact me via my contact page or GitHub.

Contributing

Contributions are welcome!

Feel free to file issues on the dedicated page. Thanks to the contributors who submitted features and bugfixes!

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.0.1.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

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

htmldate-1.0.1-py3-none-any.whl (37.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: htmldate-1.0.1.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for htmldate-1.0.1.tar.gz
Algorithm Hash digest
SHA256 c0061640b9c126832aea9b90d6c51dbe1c999b6cf77195c2de1bfb1d37247122
MD5 932f1732e805b46492bc775139146315
BLAKE2b-256 fdca1aa2a228dc54b80094b5e52b3c75bfae0396439364ac3f6c85a287082065

See more details on using hashes here.

File details

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

File metadata

  • Download URL: htmldate-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 37.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.22.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/18.0.1 rfc3986/2.0.0 colorama/0.4.3 CPython/3.8.10

File hashes

Hashes for htmldate-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 09ea467a0cd3cb814230f119a1e83aec4001b06c0fc414f080ea5a0efc70b01f
MD5 015ca95d2e71598320fcf08bfa896226
BLAKE2b-256 4b12f1cd080eff5010fe25ff8cc2433f88ed16efb9c0d7c16bfee4d50afc774d

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