htmldate is a Python library designed for fast and robust extraction of original and updated publication dates from URLs and web pages. It is actively maintained with frequent minor releases, often addressing bug fixes, dependency updates, and improvements to extraction heuristics.
pip install htmldateVerified import paths — ran on the pinned version, not inferred.
To use `htmldate`, import the `find_date` function. It can extract dates directly from a URL or from an HTML string. When providing an HTML string, it's often useful to also provide the `url` parameter for better relative path resolution and more accurate heuristics. The `originaldate` parameter allows you to prioritize the earliest found date (original publication) over potentially updated dates.
Ensure your project runs on Python 3.8 or a newer version.
Review your code if you used `originaldate=True` in versions prior to `1.7.0` and verify the extracted dates are as expected after upgrading.
Be aware that date extraction results might vary for some URLs when upgrading from versions older than `1.6.0` due to refined heuristics. Evaluate critical extractions after upgrade.
Ensure `requests` is correctly installed in your environment. Installing `htmldate` via `pip install htmldate` within a dedicated virtual environment is the recommended approach to automatically resolve and install its dependencies.
Ensure the 'requests' library is installed in your Python environment. When installing 'htmldate' via pip, 'requests' should be automatically installed as a dependency. If running custom scripts, explicitly install 'requests' (e.g., `pip install requests`).
Reinstall `lxml` to ensure a clean and compatible installation: `pip uninstall lxml` followed by `pip install lxml`. If using a specific Python 3 environment, use `pip3`.
First, update `htmldate` to the latest version (`pip install -U htmldate`) as bug fixes related to date extraction heuristics are frequent. If the issue persists, the target webpage may genuinely lack discernible date metadata for the library to find.
Install the `htmldate` package using pip: `pip install htmldate`. If already installed, verify that you are running your script with the Python interpreter where `htmldate` was installed (e.g., by activating the correct virtual environment).
If encountering issues with the `[speed]` extra, install `htmldate` without it: `pip install htmldate`. `htmldate` will then fall back to `charset_normalizer` for character detection, which is typically more broadly compatible. If `cchardet` was partially installed and causing issues, uninstall it explicitly: `pip uninstall cchardet`.