# xkcd Comics Scraper - Titles, Alt Text, Transcripts & Images (`ninhothedev/xkcd-scraper`) Actor

$0.3/1K 🔥 Fast xkcd scraper! Comics — title, alt text, image, transcript & date. No key. JSON, CSV, Excel or API in seconds. Grab latest, ranges or specific numbers & pull thousands for content & NLP ⚡

- **URL**: https://apify.com/ninhothedev/xkcd-scraper.md
- **Developed by:** [ninhothedev](https://apify.com/ninhothedev) (community)
- **Categories:**
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $0.30 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

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

## xkcd Comics Scraper 🖊️

Scrape [xkcd](https://xkcd.com) comics into clean, structured JSON — **title, alt text (the mouseover joke), image URL, transcript and publication date** — with no API key, no login, and no browser. The Actor talks directly to xkcd's official, public JSON API, so it is fast, reliable, and **datacenter-proxy friendly** (you don't need residential proxies).

Grab the **latest N comics**, a **hand-picked list of numbers**, or an **entire range** — up to 1,000 comics per run.

***

### ✨ Features

- **Clean JSON output** — one tidy record per comic, every field nullable and predictable.
- **Alt text included** — the famous xkcd hover/title-text joke, which most scrapers miss.
- **Transcript field** — community transcript text where available (great for NLP / search).
- **Three modes** — `latest`, `comics` (specific numbers), `range`.
- **ISO dates** — xkcd's split year/month/day is normalised to `YYYY-MM-DD`.
- **Handles comic #404 gracefully** — [that comic intentionally does not exist](https://xkcd.com/404) and is skipped, not fatal.
- **No API key, no proxies required** — runs cheaply on the free/starter plan.

***

### 🚀 Input

| Field | Type | Description |
|-------|------|-------------|
| `mode` | select | `latest`, `comics`, or `range`. |
| `latestCount` | integer | For `latest`: how many recent comics (default `20`). |
| `numbers` | array | For `comics`: e.g. `[353, 1234]`. |
| `fromNum` | integer | For `range`: first comic number (inclusive). |
| `toNum` | integer | For `range`: last comic number (inclusive). |
| `maxItems` | integer | Hard cap per run (default `100`, max `1000`). |

#### Example — latest 20 comics

```json
{ "mode": "latest", "latestCount": 20 }
```

#### Example — specific comics

```json
{ "mode": "comics", "numbers": [353, 1234, 936] }
```

#### Example — a range

```json
{ "mode": "range", "fromNum": 1, "toNum": 100, "maxItems": 100 }
```

***

### 📦 Output

Each dataset item:

```json
{
  "num": 353,
  "title": "Python",
  "alt": "I wrote 20 short programs in Python yesterday.  It was wonderful.  Perl, I'm leaving you.",
  "img": "https://imgs.xkcd.com/comics/python.png",
  "date": "2007-12-05",
  "transcript": "[[ A stick figure is floating in the sky ]] ...",
  "url": "https://xkcd.com/353/",
  "scraped_at": "2026-07-18T08:00:00+00:00"
}
```

***

### 💸 Pricing

This Actor is lightweight — it hits a plain JSON endpoint per comic, so runs are cheap. As a rule of thumb, expect roughly **~$0.50 per 1,000 comics** in platform usage, depending on your plan and memory settings. Small runs (the latest 20) cost a fraction of a cent.

***

### 🎯 Use cases

- **Content & newsletters** — embed the latest comic, alt text and link automatically.
- **NLP / ML datasets** — build a labelled corpus of captions, alt text and transcripts for text analysis, humour research, or embeddings.
- **Fan apps & bots** — power a "random xkcd" Slack/Discord bot, a widget, or a mobile app.
- **Archiving** — snapshot the full xkcd back-catalogue with stable image URLs and metadata.

***

### 🆚 Why this Actor?

| | This Actor | Manual scraping | RSS feed |
|---|---|---|---|
| Alt text (hover joke) | ✅ | ⚠️ fragile HTML parsing | ❌ |
| Transcript | ✅ | ⚠️ | ❌ |
| Specific numbers / ranges | ✅ | ⚠️ | ❌ latest only |
| ISO dates | ✅ | ❌ | ⚠️ |
| No proxies needed | ✅ | depends | ✅ |

***

### 🔗 Related Actors

- [Rick and Morty Scraper](https://apify.com/ninhothedev/rick-and-morty-scraper)
- [Pokémon Scraper](https://apify.com/ninhothedev/pokemon-scraper)
- [Wikipedia Scraper](https://apify.com/ninhothedev/wikipedia-scraper)
- [Reddit Scraper](https://apify.com/ninhothedev/reddit-scraper)

***

**Keywords:** xkcd scraper, xkcd api, webcomic scraper, comic scraper, alt text, comic transcript, nlp dataset, randall munroe, geek humor, comic archive.

# Actor input Schema

## `mode` (type: `string`):

How to select comics. 'latest' = the N most recent comics. 'comics' = an explicit list of comic numbers. 'range' = every comic between fromNum and toNum.

## `latestCount` (type: `integer`):

Used when mode = 'latest'. How many of the most recent comics to scrape, walking backwards from the newest.

## `numbers` (type: `array`):

Used when mode = 'comics'. An array of specific xkcd comic numbers to scrape, e.g. \[353, 1234]. Comic 404 does not exist and is skipped.

## `fromNum` (type: `integer`):

Used when mode = 'range'. The first comic number in the range (inclusive).

## `toNum` (type: `integer`):

Used when mode = 'range'. The last comic number in the range (inclusive).

## `maxItems` (type: `integer`):

Hard cap on the number of comics scraped in a single run. Protects against runaway ranges. Max 1000.

## Actor input object example

```json
{
  "mode": "latest",
  "latestCount": 20,
  "numbers": [
    353,
    1234
  ],
  "fromNum": 1,
  "toNum": 20,
  "maxItems": 100
}
```

# Actor output Schema

## `overview` (type: `string`):

No description

# 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 = {
    "numbers": [
        353,
        1234
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("ninhothedev/xkcd-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 = { "numbers": [
        353,
        1234,
    ] }

# Run the Actor and wait for it to finish
run = client.actor("ninhothedev/xkcd-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 '{
  "numbers": [
    353,
    1234
  ]
}' |
apify call ninhothedev/xkcd-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,ninhothedev/xkcd-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/xigyA8qIr4AhKdsRC/builds/XmbqABi8yhZshOJhQ/openapi.json
