Vexaloom Labs

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.

FieldTypeRequiredDescription
postUrlsarrayrequiredPost 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.
maxCommentsintegeroptionalMaximum number of comments to scrape from each post (including nested replies).
commentSortstringoptionalHow to sort the comment threads.
includePostbooleanoptionalWhen enabled, the parent post metadata is emitted as the first record of each thread.
postedAfterstringoptionalOnly keep comments created on or after this date (UTC).
postedBeforestringoptionalOnly keep comments created on or before this date (interpreted as the end of that day, UTC).
minDepthintegeroptionalOnly 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.
maxDepthintegeroptionalOnly 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.
minCommentScoreintegeroptionalOnly keep comments with a score (upvotes minus downvotes) at or above this value. Leave empty for no limit.
maxCommentScoreintegeroptionalOnly keep comments with a score (upvotes minus downvotes) at or below this value. Leave empty for no limit.
onlyOPbooleanoptionalWhen enabled, only comments written by the post's original author are kept.
excludeDeletedRemovedbooleanoptionalWhen enabled, comments that Reddit marks as deleted or author-deleted are dropped (no real content left to scrape).
excludeCollapsedbooleanoptionalWhen enabled, comments Reddit collapses by default (low score or crowd control) are dropped.
authorsarrayoptionalOnly keep comments written by these Reddit usernames (case-insensitive). Leave empty to keep comments from all authors.
excludeAuthorsarrayoptionalDrop 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).
keywordsarrayoptionalOnly keep comments whose body contains at least one of these keywords or phrases (case-insensitive substring match). Leave empty to keep all comments.
excludeKeywordsarrayoptionalDrop 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.
minAwardsintegeroptionalOnly keep comments with at least this many total awards. Leave empty for no limit.
minCommentLengthintegeroptionalOnly 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.
maxCommentLengthintegeroptionalOnly 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.
focusOnTargetCommentbooleanoptionalWhen 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.
commentContextintegeroptionalHow 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.