# Website Image Scraper (`crawlerbros/website-image-scraper`) Actor

Extract every image URL from a website. Crawls the start page (and optionally internal links up to a configurable depth), parses `<img>` tags, `<picture>`/`<source>`, `srcset` candidates, and CSS `background-image` declarations. HTTP-only, no proxy or browser needed.

- **URL**: https://apify.com/crawlerbros/website-image-scraper.md
- **Developed by:** [Crawler Bros](https://apify.com/crawlerbros) (community)
- **Categories:** Automation, Developer tools, Other
- **Stats:** 123 total users, 24 monthly users, 98.8% runs succeeded, 1 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.00 / 1,000 results

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.
Since this Actor supports Apify Store discounts, the price gets lower the higher subscription plan you have.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

Actors are web data automations that power AI and operations. They run on the Apify platform to scrape websites, process data, connect APIs, and automate workflows.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

- **AI agents and MCP clients** — the [Apify MCP server](https://docs.apify.com/integrations/mcp.md) at `https://mcp.apify.com` (remote, streamable HTTP, OAuth on first use).
- **Agentic workflows and local Actor development** — [Agent Skills](https://apify.com/.well-known/agent-skills/index.json) with the [Apify CLI](https://docs.apify.com/cli/docs.md): `npm install -g apify-cli`, then `apify login`.
- **JavaScript/TypeScript projects** — the official [JS/TS client](https://docs.apify.com/api/client/js/docs.md): `npm install apify-client`.
- **Python projects** — the official [Python client](https://docs.apify.com/api/client/python/docs.md): `pip install apify-client`.
- **Any other language** — the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).

# README

## Website Image Scraper

Extract every image URL from a website. Crawls the start page (and optionally internal links up to a configurable depth), then parses `<img>` tags, `<picture>`/`<source>`, `srcset` candidates, `<link rel="icon">`, and CSS `background-image` declarations. HTTP-only — no browser, no proxy, no API key.

### What it does

- **Pull every image URL referenced on a page** — `<img src>`, lazy-loaded `data-src`, srcset candidates, picture sources, favicons, inline `style="background-image: url(https://apify.com/...)"`.
- **Crawl deeper** — follow internal links up to `maxCrawlDepth` (same host only) to grab images from linked pages too.
- **Filter by format** — restrict to specific extensions (e.g. only SVG, only WebP/AVIF).
- **Bounded** — `maxImagesPerPage` and `maxTotalImages` keep runs cost-predictable on large galleries.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `startUrl` | string (required) | `https://apify.com` | Page to start crawling. Must be `http://` or `https://`. |
| `maxCrawlDepth` | integer | `1` (0–5) | 0 = only the start URL; 1+ = follow internal links one level (same host only). |
| `maxImagesPerPage` | integer | `200` (1–5000) | Cap per page — keeps pathological galleries bounded. |
| `maxTotalImages` | integer | `1000` (1–50000) | Hard cap on total images emitted across the whole run. |
| `imageExtensions` | array | `[jpg, jpeg, png, gif, webp, svg, avif, bmp, ico]` | Only URLs whose path ends in one of these are kept. |
| `includeBackgroundImages` | boolean | `true` | Also extract from inline `style="background-image: url(https://apify.com/...)"`. |
| `userAgent` | string | (Chrome 131) | Optional UA override. |

#### Example input

```json
{
  "startUrl": "https://apify.com/",
  "maxCrawlDepth": 1,
  "maxImagesPerPage": 200,
  "maxTotalImages": 500,
  "imageExtensions": ["jpg", "png", "webp", "svg"],
  "includeBackgroundImages": true
}
```

### Output

One record per unique image URL. Empty fields are omitted (no nulls).

```json
{
  "url": "https://apify.com/static/hero.jpg",
  "sourcePage": "https://apify.com/",
  "pageTitle": "Apify · The full-stack web-scraping & automation platform",
  "alt": "Apify hero image",
  "hasAltText": true,
  "title": "Apify",
  "width": 1200,
  "height": 600,
  "extension": "jpg",
  "discoveredVia": "img-tag",
  "mimeTypeHint": "image/jpeg",
  "crawlDepth": 0,
  "scrapedAt": "2024-12-16T14:23:11+00:00"
}
```

#### Output fields

- **`url`** — absolute URL of the image (data: URIs and javascript: pseudo-URLs are filtered out).
- **`sourcePage`** — the page where the image was discovered.
- **`pageTitle`** — `<title>` of the page where the image was found (handy for grouping the dataset by page name).
- **`alt`** — `alt` attribute of the `<img>` tag (when present).
- **`hasAltText`** — derived boolean: `true` when `alt` is present and non-empty. Lets you filter accessibility issues without testing for field presence.
- **`title`** — `title` attribute (when present).
- **`width`** / **`height`** — explicit pixel dimensions from the tag (only emitted when numeric).
- **`extension`** — lowercase file extension parsed from the URL path (e.g. `"jpg"`, `"svg"`, `"webp"`). Useful for format-bucket aggregations.
- **`discoveredVia`** — one of `img-tag`, `srcset`, `picture-source`, `link-icon`, `css-background`.
- **`mimeTypeHint`** — derived from the file extension (e.g. `image/png`, `image/svg+xml`).
- **`crawlDepth`** — depth at which the page was crawled (0 = startUrl).
- **`scrapedAt`** — ISO-8601 timestamp.

### Use cases

- **Content audits** — see every image a website serves up, broken down by source (img tag vs CSS background).
- **Asset inventory** — pull all logos, hero images, and icons from a competitor or brand site.
- **Format migration** — find every JPEG/PNG to convert to WebP/AVIF, or every PNG to convert to SVG.
- **SEO / accessibility** — list images with `hasAltText: false` to flag accessibility issues at a glance.

### FAQ

**Does it download the image binaries?**
No. The actor only collects URLs and metadata. Combine with a separate downloader (or pipe URLs into Apify's standard "URL list" actor) if you need the bytes.

**Does it work on JavaScript-rendered pages?**
Mostly no. This scraper is HTTP-only — it sees the server-rendered HTML, not what runs after the page boots. If a site lazy-loads images via React/Vue, you may only see fallback / placeholder images. For SPA-rendered content, use a Playwright-based actor instead.

**Can I limit it to a single page?**
Set `maxCrawlDepth: 0`. Only the start URL is fetched.

**Does it follow external links?**
No. Internal-link crawling only follows links to the same host as `startUrl` to keep cost and scope bounded.

**What if the site has no images at all?**
You get a single sentinel record `{"type": "website_image_scraper_error", "reason": "no_images_found"}` so the dataset is non-empty. The run still completes successfully.

**How does it deduplicate?**
By absolute URL. The same image referenced from multiple pages produces one record (the first-seen page is recorded as `sourcePage`).

# Actor input Schema

## `startUrl` (type: `string`):

The page to start crawling from (e.g. 'https://example.com/'). The actor extracts images from this page and, if `maxCrawlDepth >= 1`, follows internal links to additional pages on the same host.

## `maxCrawlDepth` (type: `integer`):

0 = only the start URL. 1 = also follow links found on the start URL (same host only). Higher values widen the crawl but cost more time.

## `maxImagesPerPage` (type: `integer`):

Cap on how many images are extracted from a single page. Pathological gallery pages can list hundreds of duplicates; this keeps runs bounded.

## `maxTotalImages` (type: `integer`):

Hard cap on the total number of image records pushed across all crawled pages. The crawl stops once this many images are emitted.

## `imageExtensions` (type: `array`):

Only image URLs whose path ends in one of these extensions are kept. Drop entries to filter to a subset (e.g. only \['svg']) or extend with custom formats.

## `includeBackgroundImages` (type: `boolean`):

Also extract images referenced via inline `style="background-image: url(https://apify.com/...)"` attributes. Disable to only collect `<img>`-sourced images.

## `userAgent` (type: `string`):

Override the default Chrome User-Agent string. Most sites accept the default; only set this if a target server filters by UA.

## Actor input object example

```json
{
  "startUrl": "https://apify.com/",
  "maxCrawlDepth": 1,
  "maxImagesPerPage": 200,
  "maxTotalImages": 1000,
  "imageExtensions": [
    "jpg",
    "jpeg",
    "png",
    "gif",
    "webp",
    "svg",
    "avif",
    "bmp",
    "ico"
  ],
  "includeBackgroundImages": true
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "startUrl": "https://apify.com/",
    "maxCrawlDepth": 1,
    "maxImagesPerPage": 200,
    "maxTotalImages": 1000,
    "imageExtensions": [
        "jpg",
        "jpeg",
        "png",
        "gif",
        "webp",
        "svg",
        "avif",
        "bmp",
        "ico"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("crawlerbros/website-image-scraper").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "startUrl": "https://apify.com/",
    "maxCrawlDepth": 1,
    "maxImagesPerPage": 200,
    "maxTotalImages": 1000,
    "imageExtensions": [
        "jpg",
        "jpeg",
        "png",
        "gif",
        "webp",
        "svg",
        "avif",
        "bmp",
        "ico",
    ],
}

# Run the Actor and wait for it to finish
run = client.actor("crawlerbros/website-image-scraper").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "startUrl": "https://apify.com/",
  "maxCrawlDepth": 1,
  "maxImagesPerPage": 200,
  "maxTotalImages": 1000,
  "imageExtensions": [
    "jpg",
    "jpeg",
    "png",
    "gif",
    "webp",
    "svg",
    "avif",
    "bmp",
    "ico"
  ]
}' |
apify call crawlerbros/website-image-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,crawlerbros/website-image-scraper"
        }
    }
}

```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/jrE2aoBNygYcK5iMn/builds/5lafNCefriCSMGxiM/openapi.json
