How to get a website's favicon in Python
Checked on 2026-11-24.
A website names its icon in its own HTML: a link element with rel="icon", one or several, in different sizes. When a page declares none, browsers may try /favicon.ico at the root of the site, and a site with a web app manifest lists more icons there. A Python script reads all three in two or three requests; the Pipefetch brand endpoint returns the icon addresses it finds on a home page, next to the logo.
Where a site declares its icon
The HTML standard sets the rules:
rel="icon"points to "an icon representing the page or site". A page may list several; the browser must "select the most appropriate icon according to the type, media, and sizes attributes", and among equally appropriate ones use "the last one declared".sizesholds values such as16x16or32x32 48x48, in raw pixels. The keywordanymeans "a scalable icon, e.g. as provided by an SVG image".- For historical reasons,
rel="shortcut icon"means the same. - When a page has no icon link, user agents "may" request
/favicon.icoresolved against the page's address and use the answer as its icon. It is a convention browsers are allowed to follow, so a site does not have to have that file.
Google Search reads two more names: its favicon documentation also accepts apple-touch-icon, "an iOS-friendly icon that represents your site, per Apple's developer documentation", and apple-touch-icon-precomposed.
The third place is the web app manifest, a JSON file the page links with rel="manifest". In the Web Application Manifest specification, a W3C Working Draft last published on November 18, 2026, its icons member "specifies images that serve as iconic representations of the web application". Each icon has a src, optional sizes and type, and a purpose: any by default, maskable for an icon designed for a safe zone that may be cropped, monochrome for one used as a mask over a solid fill. The Image Resource draft parses src with the manifest's own address as the base, not the page's.
1. A script that finds every declared icon
# pip install requests beautifulsoup4
from urllib.parse import urljoin
import requests
from bs4 import BeautifulSoup
ICON_RELS = {"icon", "apple-touch-icon", "apple-touch-icon-precomposed"}
def largest_side(sizes):
"""16 for "16x16", 48 for "16x16 48x48", and the most for "any", a scalable icon."""
best = 0
if isinstance(sizes, list):
sizes = " ".join(sizes)
for size in str(sizes or "").lower().split():
if size == "any":
return 100_000
width, _, height = size.partition("x")
if width.isdigit() and height.isdigit():
best = max(best, int(width), int(height))
return best
def site_icons(url):
session = requests.Session()
res = session.get(url, timeout=15)
res.raise_for_status()
soup = BeautifulSoup(res.text, "html.parser")
icons, manifest = [], None
for link in soup.find_all("link", href=True):
rel = {token.lower() for token in link.get("rel", [])} # "shortcut icon" is two tokens
if rel & ICON_RELS:
icons.append({"url": urljoin(res.url, link["href"]), "sizes": link.get("sizes"), "from": "link"})
elif "manifest" in rel and manifest is None:
manifest = urljoin(res.url, link["href"])
if manifest:
try:
for icon in session.get(manifest, timeout=15).json().get("icons", []):
purpose = str(icon.get("purpose") or "any").split()
if icon.get("src") and "any" in purpose:
# src is relative to the manifest's own address, not to the page's
icons.append({"url": urljoin(manifest, icon["src"]), "sizes": icon.get("sizes"), "from": "manifest"})
except (requests.exceptions.RequestException, ValueError, AttributeError):
pass
if not icons:
fallback = urljoin(res.url, "/favicon.ico") # what browsers may try when a page declares no icon
try:
if session.get(fallback, timeout=15).ok:
icons.append({"url": fallback, "sizes": None, "from": "/favicon.ico"})
except requests.exceptions.RequestException:
pass
return sorted(icons, key=lambda icon: largest_side(icon["sizes"]), reverse=True)
for icon in site_icons("https://stripe.com"):
print(icon["from"], icon["sizes"], icon["url"])Beautiful Soup stores rel as a list of its values, which is why "shortcut icon" matches without a special case; the tokens are lowered because the standard compares link types case-insensitively. Manifest icons are kept only when their purpose includes any, and /favicon.ico is tried only when nothing is declared, as the standard describes for browsers. The list comes back largest first, by the sizes the site states.
Where it stops:
- The sizes are what the page says. The standard requires them to be true, but only opening the image tells you its real dimensions, and an ICO file can hold several images of different sizes.
- An icon a script adds after the page loads is not in the HTML
requestsreceives. - Some sites answer scripts with 403 or a challenge page, and some icons sit on other hosts with rules of their own.
- You get addresses. Download and keep the files you need, and remember the icon is the site owner's.
2. The favicon package
The favicon package on PyPI does a similar search. Its README returns Icon objects with url, width, height and format, passes keyword arguments on to Requests, and takes the first icon as the largest.
# pip install favicon
import favicon
icons = favicon.get("https://stripe.com", timeout=15) # keyword arguments go to requests
for icon in icons:
print(icon.url, icon.width, icon.height, icon.format)Where it stops: its last release, 0.7.0, is from August 31, 2019, and there has been none since. Try it on your sites before you depend on it.
Answers online also point to an address on google.com that returns any site's icon. We found no Google documentation for it: Google's favicon page is about how Search shows a site's icon. This guide does not build on it.
3. The brand endpoint
The Pipefetch brand endpoint reads a company's home page when you ask and returns its brand as JSON, the icons included.
import os
import requests
res = requests.get(
"https://pipefetch.com/v1/web/brand",
params={"url": "stripe.com"},
headers={"x-api-key": os.environ["PIPEFETCH_API_KEY"]},
timeout=90,
)
if res.status_code == 404:
print(res.json()["error"]["code"]) # website_unreachable or website_blocked: not charged
else:
res.raise_for_status()
brand = res.json()["data"]
print(brand["icon"]) # the first icon found, or None
print(brand["icons"]) # every icon address found on the home page
print(brand["logo"]) # url, format and source, or NoneThe same from Node.js:
const url = new URL('https://pipefetch.com/v1/web/brand');
url.searchParams.set('url', 'stripe.com');
const res = await fetch(url, { headers: { 'x-api-key': process.env.PIPEFETCH_API_KEY } });
if (res.status === 404) {
const { error } = await res.json();
console.log(error.code); // website_unreachable or website_blocked: not charged
} else {
const { data } = await res.json();
console.log(data.icon, data.icons, data.logo);
}icons lists the icon addresses found on the home page and icon is the first of them, null when none was found. In our saved answer for stripe.com of November 18, 2026, icons holds two PNG addresses, sized 180 and 96 pixels according to Stripe's own image addresses, and logo is an SVG file the site states in its structured data. The answer also has the sharing image, the brand colors, fonts, name and socials; the reference lists every field.
Where it stops: you get addresses, not files, and no size or type for each icon: if you need the largest, look at the files. Only the home page is read, as plain HTML without JavaScript. Pipefetch does not host the files, so keep your own copies. A request costs 1 credit and most take 2 to 9 seconds. A site that does not answer within 15 seconds answers 404 website_unreachable, one that refuses automated requests 404 website_blocked, and neither costs anything. A new account has 100 free credits and needs no card. It is not an official API of the websites it reads, and Pipefetch is not affiliated with them.
Which one should you use?
| Situation | Use |
|---|---|
| Icons of a few sites, with their stated sizes and manifest icons | The script |
| A quick try in a notebook | The favicon package, knowing it is unmaintained |
| Icon, logo, colors and fonts stored with each company record, from a server | The brand endpoint |
Which size to use
For a small mark next to a name, any declared icon of 32 pixels or more will do; for a tile or a card, take the largest, a scalable any icon first. If you want the site's logo rather than its icon, the logo guide covers where sites state one. And if the icon is your own, Google's guidelines for showing it in search results ask for a square of at least 8x8 pixels, recommend one "larger than 48x48px", list BMP, GIF, ICO, PNG, JPEG, PPM and TIFF as the formats they support, and show one icon per host name.
Try it with 100 free credits. No card needed. No scraper to build or maintain. Get an API key or read the docs.
APIs used in this guide
More Websites guides
- Clearbit Logo API alternatives: get a company logo from its domain
- How to extract email addresses from a website in Python
- How to turn a web page into Markdown in Python
- How to detect what a website is built with, in Python
- How to get the contact emails and phone numbers of websites in Google Sheets
- How to build a LangChain tool that reads web pages and searches Google
- How to turn a web page into Markdown in JavaScript for RAG
- How to extract social media links from a website in Python
- How to check robots.txt in Python before you fetch a page
Guides for other sources
Every source
YouTube
- How to get a YouTube transcript in Python
- How to get a YouTube transcript in Node.js
- YouTube API quota exceeded: what the error means and how to fix it
- How to find a YouTube channel ID from a handle or URL
- How to download YouTube subtitles as SRT or VTT
- youtube-transcript-api RequestBlocked or IpBlocked: why it happens and how to fix it
- How to get YouTube comments in Python
- How to search YouTube from Python
- How to list a YouTube channel's videos in Python
- How to summarize a YouTube video with an LLM in Python
- How to get YouTube transcripts and video stats in Google Sheets
- How to get YouTube video views and likes in Python
- How to get YouTube transcripts in n8n, Make and Zapier
- LangChain YoutubeLoader fails on a server: why, and a loader that works
- How to get a YouTube channel's subscriber count in Python
- How to give Claude or Cursor access to YouTube (MCP server)
- How to get YouTube comments in Node.js
- How to analyze YouTube comments with an LLM in Python
- How to list a YouTube channel's Shorts in Python
- How to search YouTube from JavaScript
- How to get an Instagram follower count in Python
- Instagram Basic Display API alternatives: what to use after the shutdown
- Instaloader 401 Unauthorized, 429 and "Login required": what to do
- How to calculate an Instagram engagement rate in Python
- How to get an Instagram follower count in Node.js
- How to get Instagram follower counts in Google Sheets
- How to get Instagram Reel views in Python
TikTok
- How to get a TikTok video's views and likes in Python
- How to get the comments of a TikTok video in Python
- How to get a TikTok follower count in Python
- TikTok Research API: who can get access, and what to do if you cannot
- How to get TikTok video views, likes and shares in Node.js
- How to get TikTok views, likes and follower counts in Google Sheets
- How to get a Facebook Page's posts without app review
- Is there a Facebook Marketplace API?
- Facebook Groups API alternatives after its removal in 2024
- How to get a Facebook Page's follower count and contact details in Python
- How to get Google search results in Python
- pytrends 429 TooManyRequestsError: what it means and what to do
- How to get Google Trends data in Python
- Why is Wyoming first in Google Trends?
- How to get Google search results in Node.js
- How to get Google search results into Google Sheets
- How to give an LLM live Google results with tool calling
Threads
- How to get LinkedIn company data in Python
- How to search LinkedIn jobs from Python
- How to get a LinkedIn company page's latest posts in Python