Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

htmldate

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

htmldate

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

  • 1.9.2
  • Source
  • PyPI
  • Socket score

Maintainers
1

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


Logo as PNG image

Find original and updated publication dates of any web page. 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 by multiple libraries.

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 PackagePrecisionRecallAccuracyF-ScoreTime
articleDateExtractor 0.200.8030.7340.6220.7675x
date_guesser 2.1.40.7810.6000.5140.67918x
goose3 3.1.170.8690.5320.4930.66015x
htmldate[all] 1.6.0 (fast)0.8830.9240.8230.9031x
htmldate[all] 1.6.0 (extensive)0.8700.9930.8650.9281.7x
newspaper3k 0.2.80.7690.6670.5560.71515x
news-please 1.5.350.8010.7680.6450.78434x

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.

Author

This project 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 meet the exacting standards is a significant challenge. It is often not possible to reliably determine the date of publication or modification using either the URL or the server response. For more information:

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,
}

You can contact me via my contact page or GitHub.

Contributing

Contributions are welcome as well as issues filed on the dedicated page.

Special thanks to the contributors who have submitted features and bugfixes!

Acknowledgements

Kudos to the following software libraries:

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc