# Reddit Subreddit Posts Scraper (`w3crawler/reddit-subreddit-posts-scraper`) Actor

Scrape posts from multiple Reddit subreddits in a single run with full metadata, images, videos, awards, and optional comments.

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

## Pricing

from $2.99 / 1,000 subreddit posts

This Actor is paid per event and usage. You are charged both the fixed price for specific events and for Apify platform usage.

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

Collect normalized public posts from one or more Reddit communities in a single bounded run. Choose a listing order, cap results per community, and optionally enrich each post with public detail and comment data.

### What this Actor does

- Reads public subreddit listings through Reddit's public web representations.
- Normalizes post identity, content, community, engagement, media, and provenance fields.
- Supports up to 50 communities and 1,000 saved posts per community.
- Optionally opens each public post for richer metadata and up to 20 top-level comments.
- Stops at login, CAPTCHA, WAF, geofence, device, or rate-limit controls; it does not bypass them.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `subreddits` | string array | — | Community names without `r/`. Use this or `subreddit`. |
| `subreddit` | string | — | Compatibility alias for a single community. |
| `sortBy` | string | `new` | `new`, `hot`, `top`, `rising`, or `controversial`. |
| `topTime` | string | `week` | Time window for `top` or `controversial`. |
| `maxItemsPerSubreddit` | integer | `50` | Saved-post cap for each community, from 1 to 1,000. |
| `deepScraping` | boolean | `true` | Request each public post representation for added details. |
| `includeComments` | boolean | `false` | Include bounded public comments; automatically enables detail requests. |
| `headless` | boolean | `true` | Run Chromium without a visible window. |
| `proxyConfiguration` | object | Apify Proxy | Standard Apify proxy configuration. A proxy does not bypass access controls. |

Compatibility aliases `sort`, `maxItems`, and `maxPostsPerSubreddit` remain accepted. Unknown fields and invalid values fail before crawling.

#### Example input

```json
{
  "subreddits": ["javascript", "webdev"],
  "sortBy": "new",
  "maxItemsPerSubreddit": 10,
  "deepScraping": false,
  "includeComments": false,
  "proxyConfiguration": { "useApifyProxy": true }
}
```

### Dataset output

Every dataset item is a real post record with `recordType: "subreddit_post"`. Core fields include `position`, `postId`, `postFullname`, `postTitle`, `permalink`, `subreddit`, `sourceListingUrl`, and `scrapedAt`. `postId` is bare and `postFullname` is the corresponding `t3_<postId>` value. Optional fields cover author, scores, timestamps, body text, flair, media, awards, and comments.

```json
{
  "recordType": "subreddit_post",
  "position": 1,
  "postId": "example123",
  "postFullname": "t3_example123",
  "postTitle": "Example discussion post",
  "permalink": "https://www.reddit.com/r/example/comments/example123/example_post/",
  "subreddit": "example",
  "score": 42,
  "numComments": 8,
  "sourceListingUrl": "https://www.reddit.com/r/example/new/?sort=new&t=week",
  "extractionMethod": "reddit-subreddit-rendered-json-or-dom",
  "scrapedAt": "2025-01-02T03:04:05.000Z"
}
```

You can download the dataset in various formats such as JSON, HTML, CSV, or Excel.

The default key-value store also contains `OUTPUT`, a run summary with requested scope, settings, records stored, failures, blocked requests, and an explicit `dataAvailable` flag. If no usable posts are available, the default dataset contains one four-field diagnostic record; diagnostics are never represented as successful post rows.

### Limits and cost control

The Actor uses one listing request at a time, no blocked-request retries, bounded pagination, and at most three concurrent detail tabs. Disable `deepScraping` when listing fields are sufficient. Usage may include browser compute, proxy traffic, and the configured per-dataset-item event price.

### Public-data and responsible use

This Actor reads only publicly available Reddit web data. It does not log in, alter browser identity, defeat challenges, use protected sessions, or evade access controls. Availability varies by Reddit, network, region, and proxy tier. Follow Reddit's terms and applicable privacy and data-protection requirements.

### Local development

```bash
npm test
apify validate-schema .actor/input_schema.json
apify run --purge
```

The dataset validator rejects incomplete or malformed post rows and treats an empty dataset as a failed extraction check.

# Changelog

This Actor's version history is a separate document: https://apify.com/w3crawler/reddit-subreddit-posts-scraper/changelog.md

# Actor input Schema

## `subreddits` (type: `array`):

List of subreddit names to scrape (without r/). E.g. javascript, worldnews, AskReddit

## `subreddit` (type: `string`):

Compatibility alias for one subreddit.

## `sortBy` (type: `string`):

How to sort posts in each subreddit

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

Compatibility alias for sortBy.

## `topTime` (type: `string`):

Time period when sortBy is 'top' or 'controversial'

## `maxItemsPerSubreddit` (type: `integer`):

Maximum posts to scrape per subreddit

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

Compatibility alias for maxItemsPerSubreddit.

## `maxPostsPerSubreddit` (type: `integer`):

Compatibility alias for maxItemsPerSubreddit.

## `deepScraping` (type: `boolean`):

Open each post for full details: selfText, images, video, gallery, awards, metadata

## `includeComments` (type: `boolean`):

Fetch top 20 comments with nested replies for each post (requires deepScraping=true)

## `headless` (type: `boolean`):

Run browser in headless mode

## `proxyConfiguration` (type: `object`):

Optional proxy settings. Proxy availability does not bypass Reddit access controls.

## Actor input object example

```json
{
  "subreddits": [
    "javascript",
    "webdev"
  ],
  "sortBy": "new",
  "topTime": "week",
  "maxItemsPerSubreddit": 50,
  "deepScraping": true,
  "includeComments": false,
  "headless": true,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

## `dataset` (type: `string`):

Active default dataset items produced by the Actor.

## `runSummary` (type: `string`):

Subreddit scope, sorting/enrichment settings, saved posts, failures, and diagnostics.

# 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 = {
    "subreddits": [
        "javascript",
        "webdev"
    ],
    "maxItemsPerSubreddit": 50,
    "deepScraping": true,
    "includeComments": false,
    "headless": true
};

// Run the Actor and wait for it to finish
const run = await client.actor("w3crawler/reddit-subreddit-posts-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 = {
    "subreddits": [
        "javascript",
        "webdev",
    ],
    "maxItemsPerSubreddit": 50,
    "deepScraping": True,
    "includeComments": False,
    "headless": True,
}

# Run the Actor and wait for it to finish
run = client.actor("w3crawler/reddit-subreddit-posts-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 '{
  "subreddits": [
    "javascript",
    "webdev"
  ],
  "maxItemsPerSubreddit": 50,
  "deepScraping": true,
  "includeComments": false,
  "headless": true
}' |
apify call w3crawler/reddit-subreddit-posts-scraper --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,w3crawler/reddit-subreddit-posts-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/CJcCVloWPaXWGR5nh/builds/cBLLcjmJSducZDFWT/openapi.json
