Web scraping
How do I get full-size image URLs instead of thumbnails?
The large version is almost always referenced somewhere on the page: in srcset, a data attribute, the zoom link, the og:image tag or structured data. Read it from there instead of the visible src.
The answer
The src attribute holds whatever the layout displays, which on listing pages is a small thumbnail. Sites still need the large file for zoom views, social previews and retina screens, so its address is usually present in the same HTML. Check these places in order: srcset, lazy loading attributes such as data-src or data-zoom-image, the link wrapping the image, the og:image meta tag, and JSON-LD structured data. When none of them has it, the URL itself often encodes the size and can be changed.
Where large images hide
| Location | What to read |
|---|---|
srcset on img or source | the candidate with the largest w value |
data-src, data-large, data-zoom-image | lazy loading and zoom plugin attributes |
Parent <a href> | lightbox galleries link the thumbnail to the original |
<meta property="og:image"> | one main image per page, usually large |
JSON-LD image field | product schema often lists every gallery image |
| Inline state JSON | framework data blobs such as __NEXT_DATA__ |
Parsing srcset correctly
A srcset is a comma-separated list of URL and descriptor pairs. Split it, read the width, and keep the largest:
import urllib.parse
def widest_candidate(img_tag, page_url):
entries = []
for chunk in (img_tag.get("srcset") or "").split(","):
pieces = chunk.strip().split()
if len(pieces) == 2 and pieces[1].endswith("w"):
entries.append((int(pieces[1][:-1]), pieces[0]))
if not entries:
fallback = img_tag.get("data-src") or img_tag.get("src")
return urllib.parse.urljoin(page_url, fallback) if fallback else None
return urllib.parse.urljoin(page_url, max(entries)[1])
Splitting on commas works for normal URLs. If a site puts commas inside image URLs (some CDNs do, for transformation parameters), split on the pattern of a comma followed by whitespace instead.
Rewriting CDN size parameters
Image CDNs resize on the fly from parameters in the URL. Common shapes include query strings like ?w=300&h=300 or ?width=300, path segments like /300x300/ or /thumbs/, and suffixes like _small.jpg or -150x150.jpg, the last being typical of WordPress uploads. Removing the size part often returns the original, and raising the width returns a larger rendition. Test with one image in the browser before applying a rewrite rule to thousands, and verify the response: some CDNs return an error or a placeholder for sizes they do not allow.
Checking what you got
Do not trust the URL alone. Request the file and read the dimensions, or at least the Content-Length, so a rewrite that silently returns the same thumbnail is caught early. A HEAD request is enough for the size check on most servers. The page on downloading images while scraping covers saving files, naming them and avoiding duplicates.
Pages that load images with JavaScript
Galleries built in a framework may not include any image URL in the raw HTML. Look for a JSON blob in a script tag first, since the gallery data is often there in full. If not, watch the Network tab while opening the gallery: the request that returns the image list is the one to call. Structured data is covered in more depth under scraping schema.org data.
Common mistakes
- Keeping relative URLs. Resolve every value against the page URL with
urljoin, including protocol-relative ones starting with//. - Taking the first srcset entry. It is usually the smallest. Sort by width.
- Collecting placeholders. Lazy loaders put a tiny base64 GIF in
srcuntil scroll. Skipdata:URLs. - Hotlinking at scale. Download at a polite pace and respect image licenses; large files cost the site real bandwidth.
When image requests start failing
Heavy image downloading triggers rate limits sooner than page requests, and some sites put image hosts behind the same bot checks as the main site. If you start getting 403 responses or challenge pages from the image host, slow down and send the same headers and cookies your page requests use. A Referer header matching the page is often required by hotlink protection. The guide to avoiding IP bans lists further ways to keep a large download job healthy.
Common questions
Which srcset candidate is the largest?
The one with the highest w descriptor. With x descriptors, the highest density is the largest file.
Is og:image always full size?
It is usually large because social previews need it, but some sites set a cropped or resized version.
Why does my rewritten URL return the same thumbnail?
The CDN may ignore unknown parameters or cap the size. Check the returned dimensions to be sure.
Do I need a browser to find large image URLs?
Rarely. They are usually in the HTML or a JSON blob; only galleries loaded by script may need the Network tab.
Why does the image host return 403?
Hotlink protection often requires a Referer header from the site, and some hosts share the main site's bot checks.
Keep reading
- How do I download images and files while scraping?Collect absolute file URLs, stream each download to disk with the same session, and name files so reruns skip duplicates.
- Data extractionData extraction turns raw HTML or JSON into clean, typed records with a fixed schema that downstream tools can trust.
- CDNContent delivery networks cache sites near visitors and, seeing all traffic first, also run many of the bot challenges you meet.
- HTML parsingHTML parsing turns markup into a tree your code can query, and tolerant parsers rebuild broken pages the same way browsers do.