Favicon Extractor
favicon is a Python library designed to find and extract a website's favicon. It simplifies the process of locating favicons, which can be in various locations on a website. The current version is 0.7.0, released in August 2019. The release cadence appears to be infrequent.
Warnings
- deprecated The `headers` argument in `favicon.get()` was deprecated in version 0.7.0. Passing a dictionary directly to `headers` will not work as expected.
- gotcha The `favicon` library has not been updated since August 2019. While it generally works, it might not handle all modern favicon detection methods or edge cases found on newer websites. Consider alternative, more actively maintained libraries for complex scenarios.
- gotcha The `favicon.get()` function returns a list of `Favicon` objects. It is common to assume only one favicon exists or to directly access `icons[0]`. However, a website might provide multiple favicons (e.g., different sizes, formats).
Install
-
pip install favicon
Imports
- get
import favicon icons = favicon.get(url)
Quickstart
import favicon
# Example URL
url = "https://www.google.com"
# Get all favicons for the URL
icons = favicon.get(url)
# The 'icons' variable is a list of Favicon objects.
# Each Favicon object has attributes like .url, .width, .height, .format.
if icons:
# Print the URL of the first (and often best) favicon
print(f"Found favicon URL: {icons[0].url}")
# You can also access other properties
print(f"Size: {icons[0].width}x{icons[0].height}")
else:
print(f"No favicons found for {url}")