# Substack Newsletter & Archive Scraper (Markdown) (`tsun_tsun/substack-intelligence-scraper`) Actor

Fetch public Substack archives and custom domains via JSON API or RSS fallback without login cookies. Outputs engagement counts, paywall flags, clean Markdown full text, and unwrapped external outbound links.

- **URL**: https://apify.com/tsun_tsun/substack-intelligence-scraper.md
- **Developed by:** [tsun tsun](https://apify.com/tsun_tsun) (community)
- **Categories:** AI, News, Agents
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $1.05 / 1,000 substack posts

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.
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?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
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.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## 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.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Substack Newsletter & Archive Scraper (Markdown)

Pull public Substack publication archives from `/api/v1/archive` JSON (with automatic `/feed` RSS XML fallback on custom domains where archive JSON is restricted) across `.substack.com` subdomains, `substack.com/@handle` URLs, bare handles, and custom Substack domains like `lennysnewsletter.com`. No login cookies, browsers, or proxies are needed.

Each post record combines structured metadata (`publicationName`, `reactionCount`, `commentCount`, `restackCount`, `wordCount`, `audience`, `isPaywalled`, `authorNames`, `coverImage`, `podcastUrl`) with clean GitHub-Flavored Markdown and unwrapped external `outboundLinks`.

### Use cases

- Build incremental daily or weekly newsletter RAG indexes using `postedWithinDays: 2` or `publishedAfter` so older archive pages are skipped before fetching full HTML or billing.
- Track newsletter sponsors and cited tools across a roster of industry publications by analyzing unwrapped `outboundLinks`.
- Benchmark top-performing essays (`sort: "top"`) by comparing `reactionCount`, `commentCount`, `restackCount`, `wordCount`, and `isPaywalled` ratios.
- Archive public essays from custom-domain Substack writers into Notion, Airtable, or `pgvector` in clean Markdown.

### Input options

| Parameter | Type | Default | Description |
| :--- | :--- | :--- | :--- |
| `publications` | `string[]` | *(required)* | Substack URLs, custom domains, `substack.com/@handle`, or bare handles. |
| `sort` | `string` | `"new"` | Archive order: `"new"` (chronological) or `"top"` (highest-performing). |
| `maxPostsPerPublication` | `integer` | `25` | Max posts per publication (`0-1000`; `0` fetches up to `1,000`). |
| `postedWithinDays` | `integer` | `0` | Rolling recency cutoff in days (`0-3650`; `0` disables). |
| `publishedAfter` | `string` | `""` | UTC start date in `YYYY-MM-DD` format (filtered before billing). |
| `freePostsOnly` | `boolean` | `false` | Skip paywalled (`only_paid` / `founding`) posts. |
| `searchQuery` | `string` | `""` | Case-insensitive keyword match (title/subtitle, plus body when `includeFullText: true`). |
| `includeFullText` | `boolean` | `true` | Extract clean `markdownText` and unwrapped `outboundLinks`. |
| `concurrency` | `integer` | `3` | Concurrent publication workers (`1-8`). |

#### Example input

```json
{
  "publications": [
    "https://www.lennysnewsletter.com",
    "pragmaticengineer"
  ],
  "sort": "new",
  "maxPostsPerPublication": 15,
  "postedWithinDays": 30,
  "includeFullText": true,
  "freePostsOnly": false,
  "concurrency": 3
}
```

### Output structure

```json
{
  "publicationName": "Lenny's Newsletter",
  "publicationUrl": "https://www.lennysnewsletter.com",
  "postId": "159823412",
  "title": "How to tell if a startup has a moat",
  "subtitle": "Frameworks from top product leaders.",
  "slug": "how-to-tell-if-a-startup-has-a-moat",
  "canonicalUrl": "https://www.lennysnewsletter.com/p/how-to-tell-if-a-startup-has-a-moat",
  "publishedAt": "2026-11-15T14:12:08.000Z",
  "audience": "everyone",
  "isPaywalled": false,
  "type": "newsletter",
  "wordCount": 2410,
  "reactionCount": 402,
  "commentCount": 28,
  "restackCount": 19,
  "authorNames": ["Lenny Rachitsky"],
  "coverImage": "https://substackcdn.com/image/fetch/f_auto,q_auto:good/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fmoat-cover.png",
  "podcastUrl": null,
  "markdownText": "## Key Takeaways\n\n- Distribution compounds faster than isolated feature launches.",
  "outboundLinks": ["https://example.org/saas-retention-benchmark"],
  "source": "archive_api",
  "scrapedAt": "2026-11-24T18:04:51.209Z"
}
```

#### Field reference

| Field | Type | Description |
| :--- | :--- | :--- |
| `publicationName` | `string` | Resolved publication title (falls back to handle or RSS channel title). |
| `publicationUrl` | `string` | Normalized publication origin URL. |
| `postId` | `string` | Substack post ID or RSS GUID. |
| `title` | `string` | Post headline. |
| `subtitle` | `string \| null` | Post subtitle or plain-text RSS summary. |
| `slug` | `string` | Post URL slug after `/p/`. |
| `canonicalUrl` | `string` | Direct post URL. |
| `publishedAt` | `string \| null` | ISO 8601 UTC publication timestamp. |
| `audience` | `string` | `"everyone"`, `"only_paid"`, or `"founding"`. |
| `isPaywalled` | `boolean` | `true` for subscriber-only or founding posts. |
| `type` | `string` | `"newsletter"`, `"podcast"`, or `"thread"`. |
| `wordCount` | `number \| null` | Post word count. |
| `reactionCount` | `number \| null` | Total reactions (`null` on RSS fallback). |
| `commentCount` | `number \| null` | Total comments (`null` on RSS fallback). |
| `restackCount` | `number \| null` | Total Notes restacks (`null` on RSS fallback). |
| `authorNames` | `string[]` | Bylines or RSS `<dc:creator>` names. |
| `coverImage` | `string \| null` | Featured cover image URL. |
| `podcastUrl` | `string \| null` | Audio enclosure URL when present. |
| `markdownText` | `string \| null` | Clean Markdown body (`null` if `includeFullText: false`). |
| `outboundLinks` | `string[]` | Unwrapped external links with Substack CDN and image links excluded. |
| `source` | `string` | `"archive_api"` or `"rss_feed"`. |
| `scrapedAt` | `string` | ISO 8601 UTC extraction timestamp. |

### Archive fetching, link hygiene & limits

Full post HTML downloads in parallel waves of 4 per archive page while preserving chronological order, per-publication limits, and budget caps. Subscribe forms, share dialogs, paywall widgets, and button wrappers are removed prior to Markdown conversion. Inside `outboundLinks`, `substack.com/redirect/...` wrappers decode to their real destination URL while self-links, `substack.com`, `substackcdn.com`, `*.substackcdn.com`, `substack-post-media.s3.amazonaws.com`, and `<a class="image-link">` lightboxes are dropped so only editorial and sponsor links remain. Real publication titles (such as `"Lenny's Newsletter"`) are extracted directly from archive byline metadata.

On Apify Cloud (256 MB memory), a 3-post full-text run completed in `2.69 s` at `92.0 MB` peak RAM (`128 MB` minimum memory). Posts stream to the dataset without buffering entire archives in RAM, responses cap at 5 MB with 15-second timeouts and capped `Retry-After` backoff on `429`/`5xx`, DNS-level SSRF checks run across inputs and redirects, and `OUTPUT` flushes cleanly on abort.

This Actor never uses login cookies or bypasses paywalls, does not extract Substack Notes, subscriber rosters, or nested comment trees, and targets Substack publications only (for Ghost, Beehiiv, or ConvertKit sites, use [Fast Website & Sitemap Markdown Crawler for AI/RAG](https://apify.com/tsun_tsun/fast-website-markdown-crawler) or [Google News & Universal RSS/Atom Feed Scraper](https://apify.com/tsun_tsun/google-news-rss-intelligence)).

### Pay-Per-Event pricing

Pay-Per-Event billing on `apify-default-dataset-item` with **$0 actor-start fee** and **$0 proxy fees**. Skipped paywalled posts, date-filtered posts, and failed publications are never charged.

| Event (Apify Store Label) | Free / 1k | Bronze (-10%) | Silver (-20%) | Gold+ (-30%) |
| :--- | :--- | :--- | :--- | :--- |
| Substack post | `$1.50` | `$1.35` | `$1.20` | `$1.05` |

`Gold+` includes Gold, Platinum, and Diamond plans (all `-30%`, or `$0.00105` per post). Apify's **$5 monthly free credit** covers **3,333 Substack posts/month** on the Free plan.

### MCP setup

#### Claude Code

```bash
claude mcp add --transport http apify-substack \
  "https://mcp.apify.com/?tools=tsun_tsun/substack-intelligence-scraper" \
  --header "Authorization: Bearer $APIFY_TOKEN"
```

#### Claude Desktop, Cursor & Windsurf

```json
{
  "mcpServers": {
    "apify-substack": {
      "url": "https://mcp.apify.com/?tools=tsun_tsun/substack-intelligence-scraper",
      "headers": {
        "Authorization": "Bearer YOUR_APIFY_TOKEN"
      }
    }
  }
}
```

### Client SDKs & cURL

#### JavaScript / TypeScript (`apify-client`)

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

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('tsun_tsun/substack-intelligence-scraper').call({
  publications: ['https://www.lennysnewsletter.com', 'pragmaticengineer'],
  postedWithinDays: 14,
  maxPostsPerPublication: 10,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
console.log(items[0].publicationName, items[0].title, items[0].reactionCount);
```

#### Python (`apify-client`)

```python
import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("tsun_tsun/substack-intelligence-scraper").call(
    run_input={
        "publications": ["https://www.lennysnewsletter.com"],
        "publishedAfter": "2026-11-01",
        "maxPostsPerPublication": 10,
    }
)
items = client.dataset(run["defaultDatasetId"]).list_items().items
print(len(items), items[0]["canonicalUrl"])
```

#### cURL

```bash
curl -X POST "https://api.apify.com/v2/acts/tsun_tsun~substack-intelligence-scraper/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "publications": ["pragmaticengineer"],
    "postedWithinDays": 14,
    "maxPostsPerPublication": 5
  }'
```

### Frequently asked questions

#### How do `postedWithinDays` and `publishedAfter` behave if both are provided?

The stricter (more recent) cutoff wins. Under `sort: "new"`, pagination halts as soon as an entire 12-item archive page falls older than the cutoff, and skipped posts never download full HTML or incur dataset charges.

#### What data is returned for paywalled subscriber-only posts?

When `freePostsOnly: false` (default), paywalled posts (`isPaywalled: true`) return full public metadata, engagement counts, `coverImage`, and whatever public preview text Substack serves before the paywall cutoff. Set `freePostsOnly: true` to skip paid posts completely at `$0`.

#### Why do some custom domains show `source: "rss_feed"` with `null` engagement counts?

If a custom Substack domain blocks `/api/v1/archive`, the Actor automatically falls back to `/feed` RSS XML. RSS feeds do not expose like, comment, or restack counts, so those three fields return `null` while `markdownText`, `outboundLinks`, `authorNames`, and media URLs are still extracted.

#### Does `maxPostsPerPublication: 0` scrape an entire publication?

`0` raises the per-publication limit to the maximum cap of `1,000` posts per run, streaming each item to the dataset as it is parsed.

### Related Actors

Companion lightweight API Actors and free workflow templates in the [Apify Automation Toolkit](https://pie527645-cloud.github.io/apify-automation-toolkit/):

| Actor | Best paired for |
| :--- | :--- |
| [Fast Website & Sitemap Markdown Crawler for AI/RAG](https://apify.com/tsun_tsun/fast-website-markdown-crawler) | Crawl linked blogs, docs, and sponsor sites found in `outboundLinks`. |
| [Google News & Universal RSS/Atom Feed Scraper](https://apify.com/tsun_tsun/google-news-rss-intelligence) | Combine Substack coverage with real-time Google News and RSS/Atom feeds. |
| [Apple Podcasts & RSS Scraper (Host Emails & Shows)](https://apify.com/tsun_tsun/apple-podcasts-rss-scraper) | Pull podcast shows, host emails, audio URLs, and episode show notes. |
| [Wikipedia Knowledge & RAG Markdown Scraper (API)](https://apify.com/tsun_tsun/wikipedia-rag-knowledge-scraper) | Pair newsletter analysis with clean Wikipedia reference articles and Wikidata IDs. |
| [Apple App Store & Reviews Scraper (iOS Apps & Ratings)](https://apify.com/tsun_tsun/app-store-reviews-scraper) | Track consumer app reviews and release notes alongside newsletter commentary. |
| [Website Contact, Email MX/DMARC & Tech Stack Enricher](https://apify.com/tsun_tsun/website-lead-tech-enricher) | Enrich sponsor domains extracted from `outboundLinks` with contact and tech-stack data. |

# Changelog

This Actor's version history is a separate document: https://apify.com/tsun_tsun/substack-intelligence-scraper/changelog.md

# Actor input Schema

## `publications` (type: `array`):

Substack publication URLs (https://www.lennysnewsletter.com, https://example.substack.com, https://substack.com/@handle) or bare Substack handles (e.g. 'pragmaticengineer'). Automatically deduplicated.

## `sort` (type: `string`):

Fetch newest posts chronologically or highest-performing top posts from the archive API.

## `maxPostsPerPublication` (type: `integer`):

Maximum posts to extract per publication (0 fetches the entire accessible archive up to 1,000 posts).

## `postedWithinDays` (type: `integer`):

Keep only posts published within the last N days for incremental daily/weekly syncs (filtered before fetching full text or billing). Set 0 to disable.

## `publishedAfter` (type: `string`):

Optional UTC start date in YYYY-MM-DD format (e.g. '2026-11-01'). Posts published earlier are skipped before fetching full text or billing.

## `freePostsOnly` (type: `boolean`):

Skip paywalled subscriber-only and founding-member posts so only public posts are emitted.

## `searchQuery` (type: `string`):

Case-insensitive keyword filter. Searches title, subtitle, and post body when includeFullText is true (or via RSS fallback); searches title and subtitle when includeFullText is false.

## `includeFullText` (type: `boolean`):

Convert public post HTML to clean GitHub-Flavored Markdown and extract unwrapped external outboundLinks.

## `concurrency` (type: `integer`):

Number of publications processed concurrently (1 to 8).

## Actor input object example

```json
{
  "publications": [
    "https://www.lennysnewsletter.com",
    "pragmaticengineer"
  ],
  "sort": "new",
  "maxPostsPerPublication": 25,
  "postedWithinDays": 30,
  "publishedAfter": "2026-11-01",
  "freePostsOnly": false,
  "searchQuery": "pricing",
  "includeFullText": true,
  "concurrency": 3
}
```

# Actor output Schema

## `summary` (type: `string`):

JSON summary listing publications processed, posts pushed, source endpoints used, and any per-publication errors.

## `posts` (type: `string`):

Extracted Substack post records including engagement counts, clean Markdown full text, and external outbound links.

# 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 = {
    "publications": [
        "https://www.lennysnewsletter.com"
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("tsun_tsun/substack-intelligence-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 = { "publications": ["https://www.lennysnewsletter.com"] }

# Run the Actor and wait for it to finish
run = client.actor("tsun_tsun/substack-intelligence-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 '{
  "publications": [
    "https://www.lennysnewsletter.com"
  ]
}' |
apify call tsun_tsun/substack-intelligence-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,tsun_tsun/substack-intelligence-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/4atbQnJS2jvMLTLo7/builds/4WnA7TYktb8WQ6sjl/openapi.json
