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

Scrape public new, hot, top, rising, or controversial posts from one Reddit subreddit with post metadata, media, awards, and optional bounded comments.

- **URL**: https://apify.com/w3crawler/reddit-subreddit-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 Reddit community with bounded pagination and optional post/comment enrichment. Choose the listing order and time window, cap saved rows, and receive a clean dataset plus an explicit run summary.

### What this Actor does

- Reads a public subreddit listing through Reddit's public web representation.
- Supports `new`, `hot`, `top`, `rising`, and `controversial` ordering.
- Normalizes post identity, community, engagement, content, media, and provenance fields.
- Optionally requests public post detail data and up to 20 top-level comments.
- Stops at login, CAPTCHA, WAF, geofence, device, or rate-limit controls without bypassing them.

### Input

| Field | Type | Default | Description |
|---|---|---|---|
| `subreddit` | string | required | Community name without `r/`; 2–21 letters, numbers, or underscores. |
| `sortBy` | string | `new` | `new`, `hot`, `top`, `rising`, or `controversial`. |
| `topTime` | string | `week` | Time window for `top` or `controversial`. |
| `maxItems` | integer | `50` | Saved-post cap from 1 to 1,000. |
| `deepScraping` | boolean | `true` | Request each public post representation for richer 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. |

Unknown fields and invalid values fail before crawling.

#### Example input

```json
{
  "subreddit": "javascript",
  "sortBy": "new",
  "topTime": "week",
  "maxItems": 10,
  "deepScraping": false,
  "includeComments": false,
  "proxyConfiguration": { "useApifyProxy": true }
}
```

### Dataset output

Every dataset item is a real post record with `recordType: "subreddit_post"`. Required fields are `recordType`, `position`, `postId`, `postFullname`, `postTitle`, `permalink`, `subreddit`, `sourceListingUrl`, and `scrapedAt`. `postId` is bare and `postFullname` is the corresponding `t3_<postId>` value. Optional fields include author, scores, timestamps, post body, 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 contains `OUTPUT`, a JSON run summary with the 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 dataset 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
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-scraper/changelog.md

# Actor input Schema

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

Name of the subreddit to scrape (without r/). Example: javascript, worldnews, AskReddit

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

How to sort the posts

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

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

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

Maximum number of posts to scrape

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

Open each post in a parallel browser tab to extract full details: complete selfText, images, videos, gallery, awards, metadata. Recommended for rich datasets.

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

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

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

Run browser in headless mode (recommended for production)

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

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

## Actor input object example

```json
{
  "subreddit": "javascript",
  "sortBy": "new",
  "topTime": "week",
  "maxItems": 50,
  "deepScraping": true,
  "includeComments": false,
  "headless": true,
  "proxyConfiguration": {
    "useApifyProxy": true
  }
}
```

# Actor output Schema

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

Dataset containing all successfully extracted public Reddit posts.

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

Completion summary or diagnostic for the subreddit, request settings, saved records, and access status.

# 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 = {
    "subreddit": "javascript",
    "maxItems": 50,
    "deepScraping": true,
    "includeComments": false,
    "headless": true
};

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

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

```

## MCP server setup

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