# Reddit Scraper - Search Posts & Extract Comments (`thilina_jayamal/reddit-scraper`) Actor

Scrape Reddit posts, search results, and full comment threads with ease. Search Reddit by topic or extract detailed posts and comments from specific URLs, with results available in JSON, CSV, or Excel.

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

## Pricing

Pay per usage

This Actor is paid per platform usage. The Actor is free to use, and you only pay for the Apify platform usage, which gets cheaper the higher subscription plan you have.

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

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

## Reddit Scraper

This tool helps you collect information from Reddit. You can use it to search for topics or to read specific posts and their comments.

### How to Use It

The scraper has two main modes you can choose from.

> **Important Note**: The scraper does not support running both modes at the same time. If you accidentally provide inputs for both (e.g., both a topic and a list of URLs), it will only execute the mode you specifically selected in the "Mode" dropdown, and the inputs for the other mode will be ignored.

#### 1. Search Mode

Use this when you want to find posts about a specific topic.

- **Topic**: Type the word or phrase you want to search for (for example, "data analysis").
- **Max Items**: Choose how many posts you want to collect. The scraper will scroll down the Reddit search page until it finds that many posts.
- **Sort**: Choose how to order the search results (options: `relevance`, `hot`, `top`, `new`, `comments`). Default is `relevance`.
- **Time Filter**: Choose the time range for the search results (options: `all`, `year`, `month`, `week`, `day`, `hour`). Default is `all`.

#### 2. Post Details Mode

Use this when you have specific Reddit posts you want to read.

- **Start URLs**: Paste the direct links to the Reddit posts you want to scrape. The tool will visit each link and collect the main post text and all the comments inside it.

***

### What the Data Looks Like

The scraper will return a list of results. You can download these results as JSON, CSV, or Excel from Apify. Below is a simple explanation of what information you get in each mode.

#### When using Search Mode

The tool gives you a list of posts it found in the search. For every post, it collects:

- `type`: Always says "search\_result" so you know what kind of data it is.
- `postedTime`: When the post was created (like "2 days ago").
- `authorProfileUrl`: The link to the user who wrote the post.
- `title`: The title of the post.
- `description`: A short preview of the text inside the post.
- `votes`: The number of upvotes the post has.
- `comments`: The number of comments on the post.
- `postUrl`: The direct link to the post, which you can use in the "Post Details Mode" later if you want to read the comments.

**Exact format example:**

```json
[
  {
    "type": "search_result",
    "postedTime": "2 days ago",
    "authorProfileUrl": "/user/johndoe",
    "title": "Best data analysis tools in 2024",
    "description": "I am looking for a comprehensive list of...",
    "votes": "150",
    "comments": "42",
    "postUrl": "https://www.reddit.com/r/data/comments/xyz123/"
  },
  {
    "type": "search_result",
    "postedTime": "3 days ago",
    "authorProfileUrl": "/user/janedoe",
    "title": "Learning Python for beginners",
    "description": "What are the best resources to start...",
    "votes": "85",
    "comments": "12",
    "postUrl": "https://www.reddit.com/r/python/comments/abc789/"
  }
]
```

#### When using Post Details Mode

The tool gives you a list containing the full post and all of its comments. For every URL you provide, it collects the following attributes:

- `type`: Always says "post\_details".
- `url`: The link to the post you provided.
- `post`: A section containing the main details of the post itself. Inside `post`, you get:
  - `subreddit`: The name of the community where the post was created.
  - `title`: The headline or title of the post.
  - `author`: The username of the person who wrote the post.
  - `selftext`: The full body text of the post.
  - `score`: The number of upvotes the post has.
- `comments`: A list of all the comments people left. For every single comment, you get:
  - `author`: The username of the person who wrote the comment.
  - `body`: The actual text of the comment.
  - `score`: The number of upvotes the comment has.
  - `replies`: A list of any replies other people made to that specific comment. These replies have the exact same attributes (`author`, `body`, `score`, and their own `replies`), which allows you to see the entire conversation tree.

**Exact format example:**

```json
[
  {
    "type": "post_details",
    "url": "https://www.reddit.com/r/data/comments/xyz123/",
    "post": {
      "subreddit": "data",
      "title": "Best data analysis tools in 2024",
      "author": "johndoe",
      "selftext": "I am looking for a comprehensive list of...",
      "score": 150
    },
    "comments": [
      {
        "author": "janedoe",
        "body": "This is a great question. I highly recommend...",
        "score": 50,
        "replies": [
          {
            "author": "data_nerd",
            "body": "I agree with this completely!",
            "score": 12,
            "replies": []
          }
        ]
      }
    ]
  }
]
```

### Need Help?

If you have any questions or notice any problems, please let us know in the "Issues" tab. We will be happy to help!

# Actor input Schema

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

Scraping mode: 'search' to search for topics, or 'post\_details' to scrape specific URLs.

## `topic` (type: `string`):

Topic to search for (used when mode is 'search').

## `start_urls` (type: `array`):

URLs to scrape (used when mode is 'post\_details').

## `max_items` (type: `integer`):

Maximum number of search results to return (used when mode is 'search'). Default is 20.

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

Sort order for search results (used when mode is 'search').

## `time_filter` (type: `string`):

Time range for search results (used when mode is 'search').

## Actor input object example

```json
{
  "mode": "search",
  "topic": "apify web scraping",
  "start_urls": [
    {
      "url": "https://www.reddit.com/r/webscraping/"
    }
  ],
  "max_items": 20,
  "sort": "relevance",
  "time_filter": "all"
}
```

# Actor output Schema

## `results` (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 = {
    "topic": "apify web scraping",
    "start_urls": [
        {
            "url": "https://www.reddit.com/r/webscraping/"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("thilina_jayamal/reddit-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 = {
    "topic": "apify web scraping",
    "start_urls": [{ "url": "https://www.reddit.com/r/webscraping/" }],
}

# Run the Actor and wait for it to finish
run = client.actor("thilina_jayamal/reddit-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 '{
  "topic": "apify web scraping",
  "start_urls": [
    {
      "url": "https://www.reddit.com/r/webscraping/"
    }
  ]
}' |
apify call thilina_jayamal/reddit-scraper --silent --output-dataset

```

## MCP server setup

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