Image Scraper: Download Every Image From a Website

An image scraper has two jobs, harvesting every image URL and fetching the files. Live-tested commands for both halves, including the steps that fail.

MMotherlode Lab11 min read
Magpie title card: Image Scraper: Download Every Image From a Website

Saving 400 product photos by hand is a Tuesday nobody needs. An image scraper does the whole sweep: it reads a page, pulls out every image URL, and hands you a list a downloader can chew through. Those are two separate jobs, most tools do one, and this guide is what survived when I ran both against a live catalog.

The two jobs hiding in an image scraper

Job one is extraction. The images live inside HTML as <img src> attributes, CSS backgrounds, and JSON-LD blobs. A scraper reads that markup and returns clean URLs.

Job two is transfer, where a tool issues one HTTP GET per URL and writes bytes to disk. Extractors tend to be careful and polite; downloaders tend to be fast and dumb. You usually need both, and pretending one tool covers both is where most tutorials waste your time.

Here is the field, and where each option stops.

Approach What it actually does Best for Where it stops
Magpie + wget Extracts clean image URLs from page content, wget fetches the bytes Content pages, product pages, catalogs with prose Cannot download files itself; refuses pages with no readable text
Plain wget mirror Recursively follows links and grabs matching files Bare galleries, whole-site image grabs No extraction intelligence; grabs exactly what the pattern matches
gallery-dl v1.32.17 Per-site extractors that find and download in one step Known gallery and social sites it has extractors for Unknown sites fall back to a generic extractor, which is careful wget with extra steps
Browser extension Clicks through the open page and saves what it sees A handful of pages, non-technical teammates Painful past ~50 pages, no scheduling, no scripting

The rest of this guide walks the first path in detail, because it survives contact with real sites. If your target is one of the hundreds of sites gallery-dl already has an extractor for, skip to the gallery-dl section and let it do both jobs at once.

Before you start

Three things and ten minutes.

  1. wget. Preinstalled on macOS and Linux. Windows: use WSL. Every download command below is wget.

  2. Magpie, for the extraction half. Clone and build the single static Go binary:

    git clone https://github.com/motherlodelab/magpie.git
    cd magpie
    go build -o magpie ./cmd/magpie

    No API key needed for this job. Cleaning, crawling, and extraction run without one; you only pay for LLM features, which image scraping does not touch. Magpie is AGPL-3.0-or-later, with a commercial license if your employer objects.

  3. A target you are allowed to scrape. Check the site’s robots.txt, and know that images are copyrighted objects even when the scraper makes copying easy. I use books.toscrape.com, a sandbox built for exactly this, for every command below.

Step 1: Harvest every image URL on a page

Magpie’s scrape command fetches a page, strips boilerplate, and returns clean Markdown. Image links survive that cleaning as ![alt](url) lines, which makes them trivially greppable.

magpie scrape https://books.toscrape.com/catalogue/a-light-in-the-attic_1000/index.html --page-format markdown

What you should see, abridged:

![A Light in the Attic](https://books.toscrape.com/media/cache/fe/72/fe72f0532301ec28892ae79a629a293c.jpg)

# A Light in the Attic

£51.77

In stock (22 available)

That single line is your URL list. The alt text comes free, which matters more than it sounds: when you have 400 images named 0681...jpg, alt text is the only human-readable thing in the folder’s metadata.

Failure case, and it will happen: point the same command at a bare gallery page, one that is all thumbnails and no prose, and Magpie refuses.

Error: quality blocked (empty) for https://books.toscrape.com/

This is the quality gate doing its job. Magpie exists to extract content, and when a page cleans down to nothing, it returns a typed error instead of empty output. I confirmed the gate holds in raw and browser-render modes too. Image galleries are exactly the page shape it rejects.

Workaround: treat the gallery as a mirror job and skip extraction entirely (Step 3), or pull the images off individual detail pages, which have prose and pass.

Step 2: Download the list with wget

One pipeline takes you from page to files. Extract the Markdown image targets, strip tracking parameters, and feed the list to wget:

magpie scrape https://en.wikipedia.org/wiki/Magpie --page-format markdown \
  | grep -oE '!\[[^]]*\]\([^)]+\)' \
  | sed -E 's/!\[[^]]*\]\(([^)]+)\)/\1/' \
  | sed 's/?.*//' \
  | wget -i - -P images/ --wait=1 --random-wait

What each piece does:

  • grep -oE catches only image links (![...](...)), leaving ordinary page links alone.
  • The first sed strips the Markdown wrapper, leaving bare URLs.
  • The second sed deletes everything after ?. Wikipedia bakes utm_source tracking parameters into its own image URLs; downloaders don’t care, but archives and diffs do.
  • wget -i - reads URLs from stdin. --wait=1 --random-wait pauses between half a second and 1.5 seconds per request, which is the difference between a polite crawler and an IP ban. Never skip the wait flags on a site you don’t own.

I ran exactly this against the Wikipedia magpie article and got real files on disk: a 9.6 KB photo of a Eurasian magpie and an edit icon.

One caveat before you copy the parameter-stripping sed blindly: some sites sign their image URLs. An S3 or CDN link like photo.jpg?X-Amz-Signature=... stops working the moment you strip the query string; the signature is the ticket. Strip parameters only when they are tracking junk. If a URL 403s after cleaning, restore the query string for that host.

Also watch for relative paths. Product pages on the sandbox emit ../../media/cache/... in their Markdown. wget can’t resolve those without the page as context, so resolve them yourself. For a known prefix, one sed does it, and I verified the result returns HTTP 200:

sed -E 's|^(\.\./)+|https://books.toscrape.com/|'

Step 3: Bare galleries: skip the URL list and mirror

When a gallery page has no prose to extract, stop trying to be clever. wget’s mirror mode follows links and downloads anything matching a file extension:

wget -r -l 1 -nd -A jpg,png,webp --wait=1 --random-wait \
  -P gallery/ \
  https://books.toscrape.com/catalogue/category/books/travel_2/index.html
  • -r recurses, -l 1 keeps it one level deep.
  • -nd dumps everything into one directory instead of recreating the site tree.
  • -A jpg,png,webp accepts only those extensions.

On the sandbox category page this pulled 11 files in one command, the category thumbnails plus covers off the pages it links to. Zero extraction, zero LLM, one process. The failure mode is honest too: -A matches file extensions, so an image served without one, or via a URL like /image?id=42, slips past. Mirror mode is a shotgun, and sometimes a shotgun is the right tool.

Step 4: Whole catalog: crawl, dedupe, download

One page is never the real job. The real job is “every product image in the catalog,” which means following links. Magpie’s crawl command walks a site breadth-first and writes one JSONL record per page, no LLM calls, no key:

magpie crawl \
  https://books.toscrape.com/catalogue/category/books/travel_2/index.html \
  --corpus --max-pages 6 --out corpus.jsonl

What you should see:

crawl: sitemap expansion: crawl: map: GET https://books.toscrape.com/sitemap.xml: HTTP 404; continuing seed-only
crawl: run_id=75ad3dec9d0d8960-248437 pages_ok=6 pages_err=0 records=6

Six pages in 5.8 seconds, at the default one-request-per-second pace. Note the first line: the sandbox has no sitemap.xml, so Magpie said so and fell back to link-following instead of dying. Then one Python line pulls every image URL out of all six pages’ Markdown at once:

python3 -c "import json,re,sys; [print(m) for l in sys.stdin for m in re.findall(r'!\[[^\]]*\]\(([^)]+)\)', json.loads(l)['markdown'])]" \
  < corpus.jsonl | sort -u > all_urls.txt

That run produced 52 image references, 45 unique after sort -u. Deduplication matters because catalogs reuse the same cover art everywhere. From here it is the Step 2 download, with the relative-path sed inserted if your target emits relative paths. Raise --max-pages and --max-depth for bigger sites, keep --rate at its polite default of one request per second, and for full-site sweeps read how to scrape an entire website before you start, because scope flags are where crawls go wrong.

If the page shows images in your browser but the scrape comes back with no ![...] lines at all, the gallery lazy-loads. The URLs sit in data-src or srcset attributes and only move into real src attributes when JavaScript runs.

Magpie has --render browser for this, and it does populate the DOM before extracting. But the quality gate still judges the page’s text, and a gallery that is 90 percent thumbnails cleans down to nothing in text terms. My test gallery stayed blocked even in browser mode. A browser render fixes lazy loading, not a thin-content rejection.

Google Images deserves its own warning, because every second tutorial ends there. The static page is a JavaScript shell, and when I pointed a browser-rendered scrape at Google during testing, a CAPTCHA arrived after two requests. Tool pages selling a Google image scraper rarely mention that part.

Practical decision: if a handful of lazy-loaded images are the job, open the page, hit F12, and copy URLs from the Network tab. If hundreds are, gallery-dl or a purpose-built extractor beats fighting the gate. And if the site is one of the majors that blocks scrapers outright (Instagram and Pinterest are on that list), no amount of --render helps; the legal and practical limits apply before the technical ones do.

Thumbnails are not the images you want

Most scrapers return what the HTML lists, and the HTML usually lists thumbnails. A srcset attribute hides the full-resolution URLs in plain sight; it is worth reading before writing any parser.

Wikimedia adds a second trick worth knowing: its thumbnail URLs encode the size in the path, /thumb/.../250px-Photo.jpg, and deleting /thumb plus the 250px- segment gives the original file. I verified the reconstructed URL returns HTTP 200. Check if your target does something similar before settling for 250-pixel “downloads.”

Where a media scraper earns its keep

Images are usually not the whole haul, and the moment you want video or audio too, the job changes name and tools. A media scraper handles embedded video, audio, and format-specific galleries. Two tools cover most of it: yt-dlp for video streams, and gallery-dl for the site-specific gallery case.

gallery-dl sits on Python 3.8+, ships under GPLv2, and its extractors are the reason people install it: hundreds of sites, each with parsing that survives the site’s quirks. One current fact before you bookmark the repo: active development moved from GitHub to Codeberg, and the GitHub README says so at the top with a link to the announcement. Old links rot; the releases live on Codeberg now.

The trade is the same as everywhere: a per-site extractor is sharp on the site it knows and generic elsewhere. For a random corporate gallery, the generic path is careful wget with extra steps. For the sites it knows, it beats anything you’d write yourself this afternoon.

What Magpie does and doesn’t do here

Stated plainly, because this is a Partly: Magpie extracts image URLs from page content, crawls catalogs to multiply the harvest, and its crawls respect robots.txt and per-host rate limits. It does not download the images. No file downloads, no gallery mirroring, by design; it is an extraction tool, not a transfer tool. The wget half of this guide is not a workaround tacked on for this article, it is the actual division of labor I use.

What you get for the extraction half: a single static binary, zero API keys for this job, and output that dedupes cleanly because it is Markdown rather than scraped HTML soup. If your job is bigger than images (PDFs, spreadsheets, any file with a URL), the same split applies and the files guide maps it. If your job is text alongside the images, that is the same pipeline minus wget: extracting clean text is what Magpie is actually built for.

FAQ

Is it legal to download all images from a website? Legality splits in two. Fetching publicly accessible images is generally lawful; reusing them is not. Photos, illustrations, and product shots are copyrighted by default, so scraping a catalog for analysis is a different act than republishing its images. Terms of service and robots.txt add contract and politeness layers. When money or publication is involved, ask a lawyer.

How do I download all images from a website in Chrome? Install a download-images extension, open the target page, click its toolbar icon, and filter by size or type before saving. Fine for a dozen pages. It does not crawl, can’t be scripted or scheduled, and stops scaling somewhere below a hundred pages, which is exactly when the command-line routes above take over.

Can wget download only images? Yes, with -A: wget -r -l 1 -A jpg,png,webp -nd URL mirrors a page and its immediate links, keeping only files with those extensions. Two limits to know: it matches file extensions in URLs, so extension-less image endpoints slip through, and recursion depth controls scope, so set -l deliberately rather than letting it run.

How do I get full-resolution images instead of thumbnails? Read the srcset attribute first; it lists the larger variants with width descriptors. Sites built on thumbnail-in-URL patterns, like Wikimedia’s 250px- paths, let you reconstruct the original by editing the URL. If neither exists, the full-size file is not on the page, and no scraper can fetch what the server never serves.

Which one I’d pick

One-off page, ten images: the F12 Network tab, done in a minute. A content page or product catalog: Magpie for the URL harvest with alt text, wget with --wait for the bytes. A bare gallery: wget mirror mode and stop pretending extraction adds value. A gallery site with a name gallery-dl knows: gallery-dl and move on with your day.

Whatever you pick, check robots.txt first (why it matters), because the polite version of this job is the one that still works next month.

Stop renting credits.

One flat price, your machine, your keys.

Download free for Windows, macOS and Linux

Windows · macOS · Linux $49/mo flat, cancel anytime