# Reddit Scraper - Posts, Comments & Subreddits (`viralanalyzer/reddit-scraper`) Actor

Extract Reddit posts, comments, subreddit data, and user profiles.

- **URL**: https://apify.com/viralanalyzer/reddit-scraper.md
- **Developed by:** [viralanalyzer](https://apify.com/viralanalyzer) (community)
- **Categories:** Social media, News
- **Stats:** 28 total users, 2 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $5.00 / 1,000 post scrapeds

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?

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

> 🔗 [View on Apify Store](https://apify.com/viralanalyzer/reddit-scraper) | 🇺🇸 English | [🇧🇷 Português](#português)

Scrape Reddit posts, **real comment trees**, engagement metrics and sentiment from any subreddit or global search query, straight from Reddit's **public RSS feed + public `.json` comments endpoint**. Get titles, permalinks, authors, creation dates, and — optionally — full comment threads. **No API key, no login, no credentials needed.**

> **Data source:** this actor reads Reddit's public RSS/Atom feed (`https://www.reddit.com/r/{subreddit}/{sort}/.rss`) for posts, and — when `includeComments` is on — enriches up to `maxPostsWithComments` posts with **real comment trees** via Reddit's public `.json` endpoint (`/comments/{post_id}.json?limit=&depth=&sort=top`). No authentication required.
>
> ### ⚠️ Comment trees are unavailable right now (measured 2026-09-09)
>
> Reddit's public `.json` comments endpoint returns **HTTP 403 on every route we have** —
> datacenter and residential alike (9 of 9 attempts blocked in one run, while the RSS feed that
> carries the posts went through in the very same run). `includeComments` now defaults to **off**:
> leaving it on costs you ~19s of run time for a fetch that cannot succeed today. Posts are still
> delivered, and `comments_tree` stays `[]` — nothing is ever fabricated. We will flip the default
> back when the endpoint is reachable.

> **Limitations:** the RSS feed alone does not expose engagement metrics or comment threads, so without `includeComments` the following fields stay `null` / empty and are **never fabricated**:
>
> - `score`, `upvote_ratio`, `num_comments` → `null`
> - `selftext` (post body) → `null` (the feed only provides the title and a boilerplate link block)
> - `comments_tree` → `[]`
>   When comment fetching is enabled, `score`, `num_comments`, `selftext`, `upvote_ratio` and `is_video` are enriched with the **real values** from the post listing, and `comments_tree` carries the real thread (up to `commentsLimit` top-level comments × `commentsDepth` recursion). If a comment fetch fails or is blocked, the post is still returned with `comments_tree: []` — nothing is invented.

### ✨ Features

- 🔍 **Subreddit scraping** — hot, new, top, rising, controversial posts
- 🌐 **Global / in-subreddit search** — search across Reddit via the public search RSS feed
- 💬 **Real comment trees via public `.json` endpoint** — recursive reply threads (no API key) with `author`, `body`, `score`, `created_utc`, `depth`, `permalink`, `replies[]`
- 📊 **Real engagement enrichment** — when comments are fetched, `score`, `num_comments`, `selftext`, `upvote_ratio`, `is_video` are filled from the post listing (never fabricated)
- 💬 **Sentiment analysis** — PT-BR + EN support (positivo/neutro/negativo) on the post title
- 🧹 **content\_clean** — HTML-stripped text ready for ML/AI training
- ⚡ **Lightweight** — pure HTTP + RSS/Atom parse, no browser required
- 🔑 **Zero credentials** — public RSS feed, no API key or login
- 🔁 **Resilient** — retry-on-429 with backoff + request spacing between subreddits
- 🌐 **Apify Proxy** — built-in proxy support for reliability

### 📥 Input

| Field | Type | Default | Description |
|-------|------|---------|-------------|
| `subreddits` | `string[]` | `["brasil"]` | List of subreddits to scrape |
| `searchQuery` | `string` | `""` | Global search query (overrides subreddits) |
| `sort` | `enum` | `"hot"` | Sort: hot, new, top, rising, controversial |
| `time` | `enum` | `"week"` | Time filter: hour, day, week, month, year, all |
| `maxPosts` | `integer` | `10` | Maximum posts to collect |
| `maxPostsWithComments` | `integer` | `3` | How many collected posts get a real comment-tree fetch (0 = none; FREE tier capped at 1) |
| `includeComments` | `boolean` | `true` | Fetch real comment trees via Reddit's public `.json` endpoint (no API key) |
| `commentsDepth` | `integer` | `3` | Max depth for comment tree recursion (clamped to 10) |
| `commentsLimit` | `integer` | `10` | Max top-level comments per post (Reddit clamps to 100) |

#### Example Input

```json
{
  "subreddits": ["brasil", "technology"],
  "sort": "hot",
  "time": "week",
  "maxPosts": 5,
  "maxPostsWithComments": 3,
  "includeComments": true,
  "commentsDepth": 2,
  "commentsLimit": 5
}
```

### 📤 Output

Each post produces one object:

| Field | Type | Description |
|-------|------|-------------|
| `post_id` | `string\|null` | Reddit post ID (base36, from the Atom `<id>`) |
| `subreddit` | `string\|null` | Subreddit name |
| `title` | `string` | Post title |
| `selftext` | `string\|null` | Post body — `null` via RSS; **enriched with the real body** when comments are fetched |
| `author` | `string` | Author username, `[deleted]` when the feed carries none |
| `score` | `number\|null` | Net upvotes — `null` via RSS; **enriched with the real value** when comments are fetched |
| `upvote_ratio` | `number\|null` | Upvote ratio — `null` via RSS; **enriched with the real value** when comments are fetched |
| `num_comments` | `number\|null` | Comment count — `null` via RSS; **enriched with the real value** when comments are fetched |
| `url` | `string\|null` | Post URL (permalink) |
| `permalink` | `string\|null` | Reddit permalink (relative path) |
| `created_utc` | `integer\|null` | Unix timestamp (from RSS date) |
| `createdISO` | `string\|null` | Creation date in ISO 8601 (from RSS date) |
| `flair` | `string\|null` | Post flair text (best effort) |
| `is_video` | `boolean\|null` | `null` via RSS; **real boolean** on the posts enriched by the `.json` fetch |
| `content_clean` | `string` | ML-ready text from the title (no HTML) |
| `sentiment` | `string` | Title sentiment (PT-BR + EN heuristic) |
| `comments_tree` | `array` | Real comment thread. Filled only on the posts that receive a `.json` fetch — the first `maxPostsWithComments` of the run (FREE tier: 1). `[]` on every other post, and `[]` when the fetch is blocked |

#### Comment Tree Structure

Each node maps 1:1 from Reddit's public `.json` comments listing (top-level = `depth` 1):

```json
{
  "id": "m6p2abc",
  "author": "user123",
  "body": "Great post!",
  "score": 42,
  "created_utc": 1707753600,
  "depth": 1,
  "permalink": "/r/AskReddit/comments/abc123/comment/m6p2abc/",
  "replies": [
    {
      "id": "m6p3def",
      "author": "user456",
      "body": "Agreed!",
      "score": 15,
      "created_utc": 1707754200,
      "depth": 2,
      "permalink": "/r/AskReddit/comments/abc123/comment/m6p3def/",
      "replies": []
    }
  ]
}
```

### 📋 Use Cases

- **AI/ML Training Data** — Clean text with `content_clean` field, ready for NLP
- **Market Research** — Monitor discussions about brands, products, or industries
- **Sentiment Analysis** — Track community sentiment over time
- **Competitor Intelligence** — Monitor what people say about competitors
- **Content Ideas** — Find popular topics and discussions in your niche
- **Academic Research** — Collect structured data from Reddit communities
- **Community Monitoring** — Track subreddit health and engagement

### ✅ Capabilities & Limits

Stated up front, so you do not pay a run to find out.

**Built here:** `maxPostsWithComments` is a global budget shared across all subreddits, consumed first-come-first-served by the first one in the list. With 5 subreddits at `maxPostsWithComments: 3`, only the first subreddit's top 3 posts carry real `score`, `num_comments`, `upvote_ratio`, `selftext`, `is_video` and `comments_tree`; posts from the rest are still pushed and still charged, with `comments_tree: []` and those fields null.

| Input / feature | Supported | Notes |
|---|---|---|
| `subreddits` | ✅ | List of subreddits to scrape (e.g. \['brasil', 'technology', 'worldnews']) |
| `searchQuery` | ✅ | Search term across all Reddit (alternative to subreddit). Leave empty to use subreddits list. |
| `sort` | ✅ | How to sort posts |
| `time` | ✅ | Time range for 'top' sort |
| Result volume (`maxPosts`) | ⚠️ | Maximum number of posts to extract per subreddit |
| Result volume (`maxPostsWithComments`) | ⚠️ | How many of the collected posts receive a real comment-tree fetch via Reddit's public `.json` endpoint. Global budget for the whole run, default 3, max 10, FREE tier 1. Each enriched post costs one extra HTTP request (up to 3 attempts with backoff on 429/403), so it adds runtime — but no extra PPE event |
| `includeComments` | ✅ | Fetch real comment trees (via Reddit's public .json endpoint, no API key) for up to maxPostsWithComments posts |
| `commentsDepth` | ✅ | Max depth of nested comment replies to fetch (recursive; clamped to 10) |
| `commentsLimit` | ✅ | Max top-level comments per post (Reddit clamps the .json endpoint to 100) |
| Proxy | ⚠️ | Proxy settings for Reddit's IP blocks. Leave it empty and the Actor starts on the Apify datacenter proxy and only switches to RESIDENTIAL US after a request has already been blocked — retry-only, so a clean run never spends residential traffic. If no proxy is available at all, requests go out direct |

### ❓ FAQ

**Q: Do I need a Reddit API key?**
A: No! This actor reads Reddit's public RSS feed — no API key, no login, no credentials.

**Q: Why are `score`, `num_comments` and the comment tree empty?**
A: When `includeComments` is `false`, the actor uses only Reddit's public RSS feed, which does not include engagement metrics or comment threads — those fields return `null` / `[]` rather than being fabricated. Enable `includeComments` (and set `maxPostsWithComments` > 0) to enrich posts with real scores, comment counts, post bodies and full comment trees via the public `.json` endpoint.

**Q: Does `includeComments` do anything?**
A: Yes! Since v1.7 it fetches **real comment trees** via Reddit's public `.json` endpoint (no API key). The number of posts enriched is capped by `maxPostsWithComments` (FREE tier: 1 post) and the tree size by `commentsLimit` / `commentsDepth`.

**Q: What proxy should I use?**
A: The default Apify (datacenter) proxy works for the RSS feed. Residential US is available as a fallback if you hit rate limits.

**Q: Can I search across all of Reddit?**
A: Yes! Use the `searchQuery` field to search globally (or within a subreddit) via the public search RSS feed.

**Q: Does it support Portuguese content?**
A: Yes! Sentiment analysis supports both PT-BR and English keywords, and the parser handles UTF-8 titles correctly.

### 💰 Pricing

**Pay Per Event + platform usage** (you pay compute, traffic and Apify proxy):

| Event | Cost |
|--------|------|
| `post-scraped` | $0.005 per post ($5.00 / 1,000) |

There is **no** per-comment event. Comments are included in the post row when `includeComments` is on. Diagnostic rows are not charged.

### 🔗 Related Actors

- [Instagram Reels Scraper](https://apify.com/viralanalyzer/instagram-reels-scraper) — Instagram metrics
- [YouTube Fast Scraper](https://apify.com/viralanalyzer/youtube-fast-scraper) — YouTube video data
- [TikTok Video Scraper](https://apify.com/viralanalyzer/tiktok-viral-scanner) — TikTok video data

### 📝 Changelog

#### v1.7 (Current)

- 💬 **Real comment trees** — when `includeComments` is on, up to `maxPostsWithComments` posts get their thread fetched from Reddit's public `.json` endpoint (`/comments/{id}.json?limit=&depth=&sort=top`, no API key). Recursive `comments_tree` with `author`, `body`, `score`, `created_utc`, `depth`, `permalink`, `replies[]`.
- 📊 **Real engagement enrichment** — `score`, `num_comments`, `selftext`, `upvote_ratio`, `is_video` are now filled with real values from the post listing when comments are fetched (still `null` via RSS-only).
- 🛡️ **Cost control** — new `maxPostsWithComments` input (default 3, max 10; FREE tier capped at 1) + `commentsLimit`/`commentsDepth` bounds; failed/blocked comment fetches never fabricate data (`comments_tree` stays `[]`).
- ➕ Added `maxPostsWithComments` to the input schema.

#### v1.6

- 🔁 **Switched data source to Reddit's public RSS/Atom feed** — the legacy `.json` API now returns HTTP 403; the public RSS feed still works with no credentials.
- 🔑 No API key, no session cookies required.
- 🔁 Retry-on-429 with increasing backoff + request spacing between subreddits.
- ➕ Added `createdISO` (ISO 8601 date) and `sentiment` output fields.
- ⚠️ `score`, `upvote_ratio`, `num_comments`, `selftext` are now `null` and `comments_tree` is empty (not available via RSS — never fabricated).

#### v1.5

- ✅ Improved reliability and proxy handling
- ✅ Enhanced sentiment analysis (PT-BR + EN)
- ✅ Better comment tree extraction

#### v1.0

- Initial release

***

<a name="português"></a>

## Reddit Scraper

> [🇺🇸 English](#reddit-scraper) | 🇧🇷 Português

Raspe posts, **árvores de comentários reais**, métricas de engajamento e sentimento de qualquer subreddit ou busca global no Reddit, direto do **feed RSS público + endpoint público `.json` de comentários** do Reddit. Obtenha títulos, permalinks, autores, datas de criação e — opcionalmente — threads completas de comentários. **Sem API key, sem login, sem credenciais.**

> **Fonte de dados:** este actor lê o feed RSS/Atom público do Reddit (`https://www.reddit.com/r/{subreddit}/{sort}/.rss`) para os posts e — quando `includeComments` está ativo — enriquece até `maxPostsWithComments` posts com **árvores de comentários reais** via endpoint público `.json` do Reddit (`/comments/{post_id}.json?limit=&depth=&sort=top`). Sem autenticação.
>
> **Limitações:** o feed RSS sozinho não expõe métricas de engajamento nem árvore de comentários; sem `includeComments`, os campos abaixo ficam `null` / vazios e **nunca são inventados**:
>
> - `score`, `upvote_ratio`, `num_comments` → `null`
> - `selftext` (corpo do post) → `null` (o feed só traz o título e um bloco de links padrão)
> - `comments_tree` → `[]`
>   Com o fetch de comentários ativo, `score`, `num_comments`, `selftext`, `upvote_ratio` e `is_video` são enriquecidos com os **valores reais** do post listing, e `comments_tree` traz a árvore real (até `commentsLimit` comentários de nível superior × `commentsDepth` de recursão). Se o fetch falhar ou for bloqueado, o post ainda é retornado com `comments_tree: []` — nada é inventado.

### ✨ Funcionalidades

- 🔍 **Raspagem de subreddits** — posts hot, new, top, rising, controversial
- 🌐 **Busca global / no subreddit** — pesquise no Reddit via feed RSS de busca público
- 💬 **Árvores de comentários reais via endpoint público `.json`** — threads recursivas de respostas (sem API key) com `author`, `body`, `score`, `created_utc`, `depth`, `permalink`, `replies[]`
- 📊 **Enriquecimento real de engajamento** — ao buscar comentários, `score`, `num_comments`, `selftext`, `upvote_ratio`, `is_video` são preenchidos com valores reais do post listing (nunca inventados)
- 💬 **Análise de sentimento** — suporte PT-BR + EN (positivo/neutro/negativo) no título
- 🧹 **content\_clean** — texto limpo pronto para ML/IA
- ⚡ **Leve** — HTTP puro + parse RSS/Atom, sem navegador
- 🔑 **Zero credenciais** — feed RSS público, sem API key ou login
- 🔁 **Resiliente** — retry-on-429 com backoff + espaçamento entre subreddits
- 🌐 **Apify Proxy** — suporte a proxy integrado para confiabilidade

### 📥 Entrada

| Campo | Tipo | Padrão | Descrição |
|-------|------|--------|-----------|
| `subreddits` | `string[]` | `["brasil"]` | Lista de subreddits para raspar |
| `searchQuery` | `string` | `""` | Busca global (substitui subreddits) |
| `sort` | `enum` | `"hot"` | Ordenação: hot, new, top, rising, controversial |
| `time` | `enum` | `"week"` | Filtro de tempo: hour, day, week, month, year, all |
| `maxPosts` | `integer` | `10` | Máximo de posts a coletar |
| `maxPostsWithComments` | `integer` | `3` | Quantos posts coletados recebem fetch de árvore de comentários (0 = nenhum; FREE tier limitado a 1) |
| `includeComments` | `boolean` | `true` | Buscar árvores de comentários reais via endpoint público `.json` do Reddit (sem API key) |
| `commentsDepth` | `integer` | `3` | Profundidade máxima dos comentários (recursiva; limitada a 10) |
| `commentsLimit` | `integer` | `10` | Máx comentários de nível superior por post (Reddit limita a 100) |

#### Exemplo de Entrada

```json
{
  "subreddits": ["brasil", "technology"],
  "sort": "hot",
  "time": "week",
  "maxPosts": 5,
  "maxPostsWithComments": 3,
  "includeComments": true,
  "commentsDepth": 2,
  "commentsLimit": 5
}
```

### 📤 Saída

Cada post produz um objeto:

| Campo | Tipo | Descrição |
|-------|------|-----------|
| `post_id` | `string\|null` | ID do post (base36, do `<id>` do Atom) |
| `subreddit` | `string\|null` | Nome do subreddit |
| `title` | `string` | Título do post |
| `selftext` | `string\|null` | Corpo do post — `null` via RSS; **enriquecido com o corpo real** quando comentários são buscados |
| `author` | `string` | Nome do autor, `[deleted]` quando o feed não traz |
| `score` | `number\|null` | Votos líquidos — `null` via RSS; **enriquecido com o valor real** quando comentários são buscados |
| `upvote_ratio` | `number\|null` | Proporção de upvotes — `null` via RSS; **enriquecida com o valor real** quando comentários são buscados |
| `num_comments` | `number\|null` | Total de comentários — `null` via RSS; **enriquecido com o valor real** quando comentários são buscados |
| `url` | `string\|null` | URL do post (permalink) |
| `permalink` | `string\|null` | Permalink do Reddit (caminho relativo) |
| `created_utc` | `integer\|null` | Timestamp Unix (da data do RSS) |
| `createdISO` | `string\|null` | Data de criação em ISO 8601 (da data do RSS) |
| `flair` | `string\|null` | Flair do post (best effort) |
| `is_video` | `boolean\|null` | `null` via RSS; **booleano real** nos posts enriquecidos pelo fetch `.json` |
| `content_clean` | `string` | Texto limpo do título para ML |
| `sentiment` | `string` | Sentimento do título (heurística PT-BR + EN) |
| `comments_tree` | `array` | Árvore real de comentários. Preenchida só nos posts que recebem o fetch `.json` — os primeiros `maxPostsWithComments` da execução (FREE tier: 1). `[]` nos demais posts e `[]` quando o fetch é bloqueado |

### 📋 Casos de Uso

- **Dados para IA/ML** — Texto limpo com `content_clean`, pronto para NLP
- **Pesquisa de mercado** — Monitore discussões sobre marcas e produtos
- **Análise de sentimento** — Acompanhe o sentimento da comunidade ao longo do tempo
- **Inteligência competitiva** — Monitore o que falam sobre concorrentes
- **Ideias de conteúdo** — Encontre tópicos populares no seu nicho
- **Pesquisa acadêmica** — Colete dados estruturados de comunidades do Reddit
- **Monitoramento de comunidade** — Acompanhe engajamento de subreddits

### ❓ Perguntas Frequentes

**P: Preciso de API key do Reddit?**
R: Não! Este actor lê o feed RSS público do Reddit — sem API key, sem login, sem credenciais.

**P: Por que `score`, `num_comments` e a árvore de comentários vêm vazios?**
R: Quando `includeComments` é `false`, o actor usa apenas o feed RSS público do Reddit, que não inclui métricas de engajamento nem comentários — esses campos retornam `null` / `[]` em vez de serem inventados. Ative `includeComments` (e `maxPostsWithComments` > 0) para enriquecer posts com scores reais, contagem de comentários, corpo do post e árvores completas via endpoint público `.json`.

**P: O `includeComments` faz algo?**
R: Sim! Desde a v1.7 ele busca **árvores de comentários reais** via endpoint público `.json` do Reddit (sem API key). O número de posts enriquecidos é limitado por `maxPostsWithComments` (FREE tier: 1 post) e o tamanho da árvore por `commentsLimit` / `commentsDepth`.

**P: Qual proxy devo usar?**
R: O proxy padrão da Apify (datacenter) funciona para o feed RSS. Residential US fica como fallback se houver rate limit.

**P: Posso buscar em todo o Reddit?**
R: Sim! Use o campo `searchQuery` para busca global (ou dentro de um subreddit) via feed RSS de busca público.

**P: Suporta conteúdo em português?**
R: Sim! A análise de sentimento suporta palavras-chave PT-BR e inglês, e o parser lida corretamente com títulos UTF-8.

### 💰 Preços

Este actor usa precificação **Pay Per Event (PPE)**:

| Métrica | Custo |
|---------|-------|
| `post-scraped` | $0.005 por post ($5,00 / 1.000) |

Não há evento por comentário. Usage (CU/proxy) é do cliente.

### 🔗 Actors Relacionados

- [Instagram Reels Scraper](https://apify.com/viralanalyzer/instagram-reels-scraper) — Métricas do Instagram
- [YouTube Fast Scraper](https://apify.com/viralanalyzer/youtube-fast-scraper) — Dados do YouTube
- [TikTok Video Scraper](https://apify.com/viralanalyzer/tiktok-viral-scanner) — Dados do TikTok

# Actor input Schema

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

List of subreddits to scrape (e.g. \['brasil', 'technology', 'worldnews'])

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

Search term across all Reddit (alternative to subreddit). Leave empty to use subreddits list.

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

How to sort posts

## `time` (type: `string`):

Time range for 'top' sort

## `maxPosts` (type: `integer`):

Maximum number of posts to extract per subreddit

## `maxPostsWithComments` (type: `integer`):

How many of the collected posts receive a real comment-tree fetch via Reddit's public .json endpoint (increases runtime — each post costs one extra request)

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

Fetch real comment trees via Reddit's public .json endpoint. ⚠️ MEASURED 2026-09-09: this endpoint currently returns HTTP 403 on every path we have (datacenter AND residential) — 9 of 9 attempts blocked in run 6DuWS35kgXgqd09Ya, while the RSS feed that carries the posts went through in the same run. Posts are still returned with comments\_tree: \[] and nothing is fabricated, but the fetch costs ~19s of run time you pay for and cannot succeed today. Default turned OFF until the endpoint is reachable again.

## `commentsDepth` (type: `integer`):

Max depth of nested comment replies to fetch (recursive; clamped to 10)

## `commentsLimit` (type: `integer`):

Max top-level comments per post (Reddit clamps the .json endpoint to 100)

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

Proxy settings for Reddit's IP blocks. Leave it empty and the Actor starts on the Apify datacenter proxy, switching to RESIDENTIAL US only after a request was blocked (retry-only). Direct connection if no proxy is available.

## Actor input object example

```json
{
  "subreddits": [
    "AskReddit"
  ],
  "sort": "hot",
  "time": "week",
  "maxPosts": 3,
  "maxPostsWithComments": 1,
  "includeComments": false,
  "commentsDepth": 1,
  "commentsLimit": 5,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  }
}
```

# Actor output Schema

## `results` (type: `string`):

Dataset containing all scraped results. Each item follows the dataset schema.

# 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": [
        "AskReddit"
    ],
    "maxPosts": 3,
    "maxPostsWithComments": 1,
    "includeComments": false,
    "commentsDepth": 1,
    "commentsLimit": 5,
    "proxyConfiguration": {
        "useApifyProxy": true,
        "apifyProxyGroups": [
            "RESIDENTIAL"
        ],
        "apifyProxyCountry": "US"
    }
};

// Run the Actor and wait for it to finish
const run = await client.actor("viralanalyzer/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 = {
    "subreddits": ["AskReddit"],
    "maxPosts": 3,
    "maxPostsWithComments": 1,
    "includeComments": False,
    "commentsDepth": 1,
    "commentsLimit": 5,
    "proxyConfiguration": {
        "useApifyProxy": True,
        "apifyProxyGroups": ["RESIDENTIAL"],
        "apifyProxyCountry": "US",
    },
}

# Run the Actor and wait for it to finish
run = client.actor("viralanalyzer/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 '{
  "subreddits": [
    "AskReddit"
  ],
  "maxPosts": 3,
  "maxPostsWithComments": 1,
  "includeComments": false,
  "commentsDepth": 1,
  "commentsLimit": 5,
  "proxyConfiguration": {
    "useApifyProxy": true,
    "apifyProxyGroups": [
      "RESIDENTIAL"
    ],
    "apifyProxyCountry": "US"
  }
}' |
apify call viralanalyzer/reddit-scraper --silent --output-dataset

```

## MCP server setup

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