{"id":1506,"library":"htmldate","title":"htmldate","description":"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.","status":"active","version":"1.9.4","language":"python","source_language":"en","source_url":"https://github.com/adbar/htmldate","tags":["date-extraction","web-scraping","html-parsing","web-content"],"install":[{"cmd":"pip install htmldate","lang":"bash","label":"Install htmldate"}],"dependencies":[{"reason":"Core dependency for parsing HTML content efficiently.","package":"lxml","optional":false},{"reason":"Used internally by `find_date` when fetching content from URLs.","package":"requests","optional":false}],"imports":[{"symbol":"find_date","correct":"from htmldate import find_date"}],"quickstart":{"code":"import requests\nfrom htmldate import find_date\n\n# Example 1: Extract date from a URL\nurl = 'https://www.example.com/news/article'\n# For real-world usage, consider handling network errors\n# Example using a placeholder URL, replace with a real one for testing\n# html_content = requests.get(url, timeout=10).text\n\n# Using a mock HTML content for reproducibility\nhtml_content = \"\"\"\n<html><head><meta property=\"article:published_time\" content=\"2023-10-26T10:00:00Z\"></head>\n<body><h1>Latest News</h1><p>Published: October 26, 2023</p></body></html>\n\"\"\"\n\ndate_from_url = find_date(url=url, html=html_content)\nprint(f\"Date extracted from URL: {date_from_url}\")\n\n# Example 2: Extract original publication date (if available and different from updated)\n# The 'originaldate' parameter hints the extractor to prioritize the earliest date.\nhtml_content_updated = \"\"\"\n<html><head><meta property=\"article:published_time\" content=\"2023-10-26T10:00:00Z\">\n<meta property=\"article:modified_time\" content=\"2024-03-15T14:30:00Z\"></head>\n<body><h1>Latest News</h1><p>Published: October 26, 2023</p><p>Last Updated: March 15, 2024</p></body></html>\n\"\"\"\noriginal_date = find_date(html=html_content_updated, originaldate=True)\nupdated_date = find_date(html=html_content_updated, originaldate=False)\n\nprint(f\"Original Date: {original_date}\")\nprint(f\"Updated Date: {updated_date}\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your project runs on Python 3.8 or a newer version.","message":"As of `v1.9.0`, htmldate officially focuses on and requires Python 3.8 or newer. Older Python versions are no longer supported and may encounter compatibility issues or installation failures.","severity":"breaking","affected_versions":">=1.9.0"},{"fix":"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.","message":"The `originaldate` parameter behavior was fixed in `v1.7.0` to more accurately distinguish between original publication dates and updated dates from meta properties. If you relied on the previous behavior (pre-1.7.0) for this distinction, your results might change.","severity":"gotcha","affected_versions":"<1.7.0"},{"fix":"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.","message":"In `v1.6.0`, the library introduced stricter extraction patterns and replaced `lxml.html.Cleaner` for a focus on precision. This might result in `htmldate` no longer finding a date on some pages where it previously did, or extracting a different (and potentially more accurate) date.","severity":"gotcha","affected_versions":"<1.6.0"},{"fix":"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.","message":"The `requests` library, a mandatory dependency for `htmldate`, was not found in the environment, leading to a `ModuleNotFoundError` and preventing `htmldate` from functioning. This typically indicates an incomplete installation or an improperly configured environment where dependencies are not automatically resolved.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"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`).","message":"The 'htmldate' library critically depends on the 'requests' package. Failure to install 'requests' will result in a 'ModuleNotFoundError', preventing 'htmldate' from functioning.","severity":"breaking","affected_versions":"all"}],"env_vars":null,"search_vec":"'activ':26 'address':33 'bug':34 'content':54 'date':18,44 'date-extract':43 'depend':36 'design':7 'extract':12,41,45 'fast':9 'fix':35 'frequent':29 'heurist':42 'html':50 'html-pars':49 'htmldate':1,2 'improv':39 'librari':6 'maintain':27 'minor':30 'often':32 'origin':14 'page':23 'pars':51 'public':17 'python':5 'releas':31 'robust':11 'scrape':48 'updat':16,37 'url':20 'web':22,47,53 'web-cont':52 'web-scrap':46","created_at":"2026-04-09T03:50:52.113120+00:00","updated_at":"2026-04-16T15:36:34.138585+00:00","problems":[{"fix":"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`.","cause":"This error often occurs when the `lxml` library, a core dependency of `htmldate` for HTML parsing, is either not properly installed, has a corrupted installation, or an incompatible version, preventing the `etree` module from being imported correctly.","error":"ImportError: cannot import name etree"},{"fix":"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.","cause":"The `find_date()` function returns `None` when it cannot successfully extract a publication or modification date from the provided URL or HTML content. This can be due to the absence of clear date patterns on the webpage, an unsupported website structure, or a bug in an older version of the `htmldate` library.","error":"htmldate.find_date() returns None"},{"fix":"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).","cause":"This error indicates that the `htmldate` package is not installed in the Python environment currently being used, or the Python interpreter cannot locate the installed package.","error":"ModuleNotFoundError: No module named 'htmldate'"},{"fix":"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`.","cause":"The optional `[speed]` installation attempts to install `cchardet` for faster character encoding detection, but `cchardet` can have compilation or compatibility issues on certain platforms (e.g., some macOS versions), leading to installation failures or runtime problems.","error":"pip install htmldate[speed] fails or cchardet issues"}],"ecosystem":"pypi","meta_description":null,"install_score":100,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.10.0","cli_name":"htmldate","cli_version":"Htmldate 1.9.4 - Python 3.11.15","type":"library","homepage":"https://htmldate.readthedocs.io","github":"https://github.com/adbar/htmldate","docs":null,"changelog":null,"pypi":"https://pypi.org/project/htmldate/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":"verified"}}