Skip to main content

Find the creation date of web pages using a combination of tree traversal, common structural patterns, text-based heuristics and robust date extraction.

Project description

Python package License Python versions Documentation Status Travis build status Appveyor/Windows build status Code Coverage
Issue tracker:

Find original and updated publication dates of any web page. All the steps needed from web page download to HTML parsing, scraping and text analysis are included.

In a nutshell, with Python:

>>> from htmldate import find_date
>>> find_date('')
>>> find_date('', original_date=True)

On the command-line:

$ htmldate -u


htmldate finds original and updated publication dates of web pages. URLs, HTML files or HTML trees are given as input, the library outputs a date string in the desired format. 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 idiosyncracies
  2. HTML code: The whole document is then searched for structural markers: abbr/time elements and 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 disambiguation algorithm determines the best one

The module returns a date if a valid cue could be found in the document, corresponding to either the last update (default) or the original publishing statement. The output string defaults to ISO 8601 YMD format.

  • Should be compatible with all common versions of Python 3
  • Output thouroughly verified in terms of plausibility and adequateness
  • Designed to be computationally efficient and used in production on millions of documents
  • Batch processing of a list of URLs
  • Switch between original and updated date


This Python package is tested on Linux, macOS and Windows systems, it is compatible with Python 3.4 upwards. It is available on the package repository PyPI and can notably be installed with pip or pipenv:

$ pip install htmldate # pip3 install on systems where both Python 2 and 3 are installed
$ pip install --upgrade htmldate # to make sure you have the latest version
$ pip install git+ # latest available code (see build status above)

A few additional libraries can be installed to enhance coverage and speed, most importantly ciso8601 and regex (for speed) as well as dateparser (to go beyond the current focus on English or German). They may not work on all platforms and have thus been singled out although installation is recommended:

$ pip install htmldate[all] # install with all additional functionality

You can also install or update the packages separately, htmldate will detect which ones are present on your system and opt for the best available combination.

For faster processing of downloads you may also consider installing the cchardet package as well (currently not working on some macOS versions).

For infos on dependency management of Python packages see this discussion thread

With Python

>>> from htmldate import find_date
>>> find_date('')

Complete screening of the document with the extensive_search parameter:

>>> find_date('')
'2017-08-11' # has been updated since
>>> find_date('', extensive_search=False)

Already parsed HTML (that is a LXML tree object):

# simple HTML document as string
>>> htmldoc = '<html><body><span class="entry-date">July 12th, 2016</span></body></html>'
>>> find_date(mytree)
# parsed LXML tree
>>> from lxml import html
>>> mytree = html.fromstring('<html><body><span class="entry-date">July 12th, 2016</span></body></html>')
>>> find_date(mytree)

Change the output to a format known to Python’s datetime module, the default being %Y-%m-%d:

>>> find_date('', outputformat='%d %B %Y')
'18 November 2016' # may have changed since

Although the time delta between original publication and “last modified” info is usually a matter of hours or days, it can be useful to prioritize the original publication date:

>>> find_date('') # default setting
>>> find_date('', original_date=True) # modified behavior

On the command-line

$ htmldate -u
$ htmldate --help
htmldate [-h] [-v] [-f] [--original] [-m MAXDATE] [-i INPUTFILE] [-u URL]
optional arguments:
-h, --help show this help message and exit
-v, --verbose increase output verbosity
-f, --fast fast mode: disable extensive search
--original original date prioritized
-m MAXDATE, --maxdate MAXDATE
 latest acceptable date (YYYY-MM-DD)
 name of input file for batch processing (similar to wget -i)
 custom URL download

The batch mode -i takes one URL per line as input and returns one result per line in tab-separated format:

$ htmldate --fast -i list-of-urls.txt

Going further

Online documentation:

If the date is nowhere to be found, it might be worth considering carbon dating the web page, however this is computationally expensive. In addition, datefinder features pattern-based date extraction for texts written in English.


This effort is part of methods to derive information from web documents in order to build text databases for research (chiefly linguistics and natural language processing). There are web pages for which neither the URL nor the server response provide a reliable way to find when a document was published or modified. For more information:

You can contact me via my contact page or GitHub.


Thanks to these contributors who submitted features and bugfixes:

Contributions are welcome!

Feel free to file bug reports on the issues page.

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.

Files for htmldate, version 0.6.1
Filename, size File type Python version Upload date Hashes
Filename, size htmldate-0.6.1-py3-none-any.whl (31.3 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size htmldate-0.6.1.tar.gz (1.2 MB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page