- Notifications
You must be signed in to change notification settings - Fork26
Fast and robust date extraction from web pages, with Python or on the command-line
License
adbar/htmldate
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Findoriginal 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 pagedownload to HTML parsing, scraping, and text analysis are included.
The package is used in production on millions of documents and integrated intothousands of projects.
>>>fromhtmldateimportfind_date>>>find_date('http://blog.python.org/2016/12/python-360-is-now-available.html')'2016-12-23'
$ htmldate -u http://blog.python.org/2016/12/python-360-is-now-available.html'2016-12-23'
- Flexible input: URLs, HTML files, or HTML trees can be used as input(including batch processing).
- Customizable output: Any date format (defaults toISO 8601YMD).
- Detection of both original and updated dates.
- Multilingual.
- Compatible with all recent versions of Python.
Htmldate operates by sifting through HTML markup and if necessary textelements. It features the following heuristics:
- Markup in header: Common patterns are used to identify relevantelements (e.g.
link
andmeta
elements) includingOpen Graphprotocol attributes. - HTML code: The whole document is searched for structural markerslike
abbr
ortime
elements and a series of attributes (e.g.postmetadata
). - Bare HTML content: Heuristics are run on text and markup:
- In
fast
mode the HTML page is cleaned and precise patterns aretargeted. - In
extensive
mode all potential dates are collected and adisambiguation algorithm determines the best one.
- In
Finally, the output is validated and converted to the chosen format.
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 seeevaluationpage.
Htmldate is tested on Linux, macOS and Windows systems, it is compatiblewith Python 3.8 upwards. It can notably be installed withpip
(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 ishtmldate==1.8.1
.
For more details on installation, Python & CLI usage,please refer tothe documentation:htmldate.readthedocs.io
This package is distributed under theApache 2.0license.
Versions prior to v1.8.0 are under GPLv3+ license.
Initially launched to create text databases for research purposesat the Berlin-Brandenburg Academy of Sciences (DWDS and ZDL units),this project continues to be maintained but its future developmentdepends on community support.
If you value this software or depend on it for your product, considersponsoring it and contributing to its codebase. Your supportwill help maintain and enhance this package.Visit theContributing pagefor more information.
Reach out via the software repository or thecontact pagefor inquiries, collaborations, or feedback.
@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,}
- Barbaresi, A. "htmldate: A Python package to extract publicationdates from web pages",Journal of Open Source Software, 5(51), 2439, 2020. DOI:10.21105/joss.02439
- Barbaresi, A. "Generic Web Content Extraction with Open-SourceSoftware",Proceedings of KONVENS 2019, Kaleidoscope Abstracts, 2019.
- Barbaresi, A. "Efficient construction of metadata-enhanced webcorpora",Proceedings of the10th Web as Corpus Workshop(WAC-X), 2016.
Kudos to the following software libraries:
- lxml,dateparser
- A few patterns are derived from thepython-goose,metascraper,newspaper andarticleDateExtractorlibraries. This module extends their coverage and robustnesssignificantly.
About
Fast and robust date extraction from web pages, with Python or on the command-line