Use Reddit Comment Thread Scraper with Score & Keyword Filters with Python
Scrape Reddit comment threads, nested replies included, with author, score, depth, and moderation flags, filtered by date, score, author, or keyword. Optional parent post record. No API key or login.
1. Choose the data you need
Review the published README for supported collection modes, examples, and limits. The recipe below uses the current published input definition.
2. Prepare a source-based input
This JSON contains published prefills and required-field defaults. Review every value for your task before running it; it is not a promise of successful collection.
{
"commentContext": 3,
"commentSort": "confidence",
"excludeCollapsed": false,
"excludeDeletedRemoved": false,
"focusOnTargetComment": false,
"includePost": false,
"maxComments": 30,
"onlyOP": false,
"postUrls": [
"https://www.reddit.com/r/programming/comments/1vqukkf/"
]
}
Download input.example.json and save your reviewed copy as input.json.
| Field | Type | Required | Description |
|---|---|---|---|
postUrls | array | required | Post URLs, comment URLs, share links or bare post IDs. Accepted forms: full post URL (https://www.reddit.com/r/x/comments/1abc/title/), short URL (https://www.reddit.com/comments/1abc or with ?sort=top), comment URL (.../comments/1abc/title/comment/xyz/), mobile share link (https://www.reddit.com/r/x/s/token), bare post id (1abc123) or t3_1abc123. |
maxComments | integer | optional | Maximum number of comments to scrape from each post (including nested replies). |
commentSort | string | optional | How to sort the comment threads. |
includePost | boolean | optional | When enabled, the parent post metadata is emitted as the first record of each thread. |
postedAfter | string | optional | Only keep comments created on or after this date (UTC). |
postedBefore | string | optional | Only keep comments created on or before this date (interpreted as the end of that day, UTC). |
minDepth | integer | optional | Only keep comments nested at or deeper than this depth (0 = keep everything, 1 = drop top-level comments and keep only replies, 2 = keep only replies-to-replies and deeper, etc.). Leave empty for no limit. |
maxDepth | integer | optional | Only keep comments nested at or above this depth (0 = top-level comments only, 1 = top-level + first-level replies, etc.). Leave empty for no limit. |
minCommentScore | integer | optional | Only keep comments with a score (upvotes minus downvotes) at or above this value. Leave empty for no limit. |
maxCommentScore | integer | optional | Only keep comments with a score (upvotes minus downvotes) at or below this value. Leave empty for no limit. |
onlyOP | boolean | optional | When enabled, only comments written by the post's original author are kept. |
excludeDeletedRemoved | boolean | optional | When enabled, comments that Reddit marks as deleted or author-deleted are dropped (no real content left to scrape). |
excludeCollapsed | boolean | optional | When enabled, comments Reddit collapses by default (low score or crowd control) are dropped. |
authors | array | optional | Only keep comments written by these Reddit usernames (case-insensitive). Leave empty to keep comments from all authors. |
excludeAuthors | array | optional | Drop comments written by these Reddit usernames (case-insensitive), e.g. bots like AutoModerator. Leave empty to keep comments from all authors. Applied after `authors` (an author listed in both is excluded). |
keywords | array | optional | Only keep comments whose body contains at least one of these keywords or phrases (case-insensitive substring match). Leave empty to keep all comments. |
excludeKeywords | array | optional | Drop comments whose body contains any of these keywords or phrases (case-insensitive substring match), e.g. spam/boilerplate phrases. Applied after `keywords` (a keyword listed in both still excludes the comment). Leave empty to keep all comments. |
minAwards | integer | optional | Only keep comments with at least this many total awards. Leave empty for no limit. |
minCommentLength | integer | optional | Only keep comments whose body text is at least this many characters long. Useful for filtering out one-word/emoji-only noise when building NLP datasets. Leave empty for no limit. |
maxCommentLength | integer | optional | Only keep comments whose body text is at most this many characters long (Reddit's hard cap is 10,000 characters). Leave empty for no limit. |
focusOnTargetComment | boolean | optional | When a `postUrls` item is a specific comment permalink, return that comment plus its ancestor chain (see `commentContext`). Works for deeply nested targets; the target must still be publicly visible. Has no effect on plain post URLs. |
commentContext | integer | optional | How many levels of parent comments above the target comment to include when `focusOnTargetComment` is enabled (matches Reddit's own comment-permalink page). Ignored otherwise. |
3. Start an Actor run
Set APIFY_TOKEN in your environment. Python 3.10 or newer is sufficient; this recipe uses no third-party packages.
Execution may incur charges. Review current pricing on Apify. The request asks for a 120-second timeout and a charge limit; these settings are subject to Apify’s pricing and do not guarantee an all-inclusive spending cap.
import json
import os
import urllib.request
# Save the schema-derived example as input.json; review and edit it first.
with open("input.json", encoding="utf-8") as stream:
actor_input = json.load(stream)
token = os.environ["APIFY_TOKEN"]
request = urllib.request.Request(
"https://api.apify.com/v2/acts/hzfhxZwMsIQ2crhb4/runs?timeout=120&maxTotalChargeUsd=0.50",
data=json.dumps(actor_input).encode("utf-8"),
headers={"Authorization": "Bearer " + token, "Content-Type": "application/json"},
method="POST",
)
# This starts a potentially billable run. Do not automatically retry this POST.
with urllib.request.urlopen(request, timeout=40) as response:
run = json.load(response)["data"]
print("Run ID:", run["id"])
print("Status:", run["status"])
# Inspect and download results in Apify Console once the run succeeds.
4. Inspect the actual results
Open the run in Apify Console and wait for a successful completion. Use the published output schema to locate results and the dataset schema to understand declared views. Missing or optional record fields must not be treated as guaranteed values.
Reddit comment threads, nested replies included, with author, score, depth, tree path, edited/deleted flags, and parent relationships, plus an optional parent post record.
Questions before you run
Which inputs are required?
The published required fields are postUrls
What does this guide verify?
The fields, prefills, and schema links are rendered from the published build. This is a usage recipe, not a paid live extraction test. Source availability and collection results can vary.
What if the run request times out?
Check Apify Console before retrying. The first request may already have created a run. Do not automatically repeat a run-creation POST.
Generated from source build aXR6xVwyCStLrYveu and its README and schemas. Source changes regenerate this guide; no third-party editorial claims are inferred.