# Reddit scraper in Python for subreddits, posts and search

> A free 350-line Python script reads public Reddit subreddits, posts and search, no API key needed. It saved 40 top posts from 4 subreddits to CSV.

- URL: https://toolzerhub.com/blog/reddit-scraper-python
- Published: 2026-10-13
- Publisher: ToolzerHub (we sell the API this post describes)

## Short answer

- One open-source Python file reads public subreddits, posts with their first comments, search and a user's posts, with no API key.
- The script reads only the first 25 comments on a thread and has no user comments or comment search. Our Reddit API covers all three.
- ToolzerHub's Reddit API costs 1 credit per call. You get 100 free credits a month; $19 buys 10,000 credits that never expire.

You can scrape public Reddit subreddits, posts with their first comments, keyword search and a user's posts with one Python file and no API key: [toolzerhub/reddit-scraper](https://github.com/toolzerhub/reddit-scraper) on GitHub. It is 350 lines, and all five commands returned live data. For more of a thread's comments, a user's comments or comment search, use our Reddit API below.

## Install the script and run five commands

Clone the repo, install the two dependencies (`curl_cffi` and `beautifulsoup4`) and point `subreddit` at any public community. Run it on your own computer; for a server or a scheduled job, use the API below.

```bash
git clone https://github.com/toolzerhub/reddit-scraper.git
cd reddit-scraper
pip install -r requirements.txt
python reddit_scraper.py subreddit python
```

The other four commands:

```bash
python reddit_scraper.py subreddit space --sort top --time week --limit 50 -o space.json
python reddit_scraper.py about nasa dataisbeautiful python space -o about.json
python reddit_scraper.py post https://www.reddit.com/r/Python/comments/1x1t161/python_315_released/ --comments 20
python reddit_scraper.py search "web scraping" --limit 25 -o search.json
python reddit_scraper.py user nasa --limit 10
```

Every command accepts `-o file.json` to save the result. A subreddit or user can be a name (`python`, `r/python`, `u/nasa`) or a URL. One post from `user nasa`:

```json
{
  "id": "1wzz0yh",
  "title": "NASA just released 814GB of Artemis II data, including nearly 1,000 new images, in their Artemis II Preliminary Lunar Science Report",
  "url": "https://www.reddit.com/user/nasa/comments/1wzz0yh/nasa_just_released_814gb_of_artemis_ii_data/",
  "subreddit": "u_nasa",
  "author": "nasa",
  "created_at": "2026-10-07T15:09:21+00:00",
  "score": 244,
  "upvote_ratio": 1.0,
  "comment_count": 2,
  "post_type": "link",
  "flair": null,
  "content_url": "https://science.nasa.gov/feature/artemis-ii-preliminary-lunar-science-report/",
  "domain": "science.nasa.gov",
  "text": null,
  "is_pinned": false,
  "is_locked": false,
  "is_spoiler": false
}
```

Feed and user posts share these fields. `search` returns a shorter record (id, title, url, subreddit, author, date, score, comment count, NSFW flag), and `post` adds a `comments` list with `parent_id` and `depth` on each comment.

## What each command returned

All five commands returned live data in 3.1 to 12.9 seconds.

- `subreddit python` took 3.3 seconds and returned 25 posts from the hot feed, starting with the pinned daily thread.
- `subreddit space --sort top --time week --limit 50` took 6.3 seconds for 50 posts over two pages, with scores from 6 to 17,025 (median 259).
- `about` for 4 subreddits took 3.1 seconds, and for 10 subreddits 12.9 seconds. Each record has the description, weekly visitors and contributions, creation date and the full rules list. There is no member count, so r/space reports 402,528 weekly visitors instead.
- `post` on the Python 3.15 release thread took 3.3 seconds and returned the post text plus 20 comments, 14 of them replies. The thread reports 70 comments; with `--comments 200` we still got 25, because the script reads only the first batch.
- `search "web scraping" --limit 25` took 9.2 seconds and returned 25 posts from 11 subreddits.
- `user nasa --limit 10` took 6.6 seconds and returned NASA's 10 latest posts.

## Save the top posts from several subreddits to CSV

`Reddit` is a class you can import, so a list of subreddits becomes one CSV in a few lines. This file sits next to `reddit_scraper.py`, reuses one session, waits 2 seconds between subreddits and reports the ones that fail.

```python
import csv
import os
import sys
import time

from reddit_scraper import Reddit, ScrapeError

FIELDS = ["subreddit", "title", "score", "comment_count", "created_at", "url"]


def main(path, subreddits):
    reddit = Reddit(os.environ.get("HTTPS_PROXY"))  # one session for the whole list
    rows = failed = 0
    with open(path, "w", newline="", encoding="utf-8") as f:
        writer = csv.DictWriter(f, fieldnames=FIELDS, extrasaction="ignore")
        writer.writeheader()
        for name in subreddits:
            try:
                posts = reddit.subreddit(name, sort="top", period="week", limit=10)
                writer.writerows(posts)
                rows += len(posts)
            except ScrapeError as exc:
                print(f"{name}: {exc}", file=sys.stderr)
                failed += 1
            time.sleep(2)  # pause between subreddits
    print(f"wrote {rows} posts from {len(subreddits)} subreddits to {path}")
    if failed == len(subreddits):
        sys.exit(1)  # every subreddit failed: don't let a cron job think it worked


if __name__ == "__main__":
    main(sys.argv[1], sys.argv[2:])
```

```bash
python subreddits_to_csv.py top-week.csv space nasa python dataisbeautiful
```

The output, with the file path and URLs shortened:

```text
wrote 40 posts from 4 subreddits to top-week.csv
```

```csv
subreddit,title,score,comment_count,created_at,url
space,"Margaret Hamilton, computing pioneer who led software development for the Apollo program, dies at 90",17024,147,2026-10-07T22:34:43+00:00,https://www.reddit.com/r/space/comments/1x0ahqw/...
space,"Moonlight reflecting off the Amazon river, seen from the International Space Station",9924,59,2026-10-12T23:12:45+00:00,https://www.reddit.com/r/space/comments/1x4gwt8/...
space,"Abandoned under the cosmos | Southland, New Zealand",7340,34,2026-10-11T18:17:23+00:00,https://www.reddit.com/r/space/comments/1x3fba0/...
```

Each subreddit gave 10 posts. Scores and comment counts are live, so they will differ when you run it.

## Comments and search with ToolzerHub

We make ToolzerHub. Our [Reddit API](https://toolzerhub.com/apis/reddit) covers what the script can't, as JSON from any server with one API key:

| You need | Script | ToolzerHub endpoint | One call returned |
|---|---|---|---|
| Comments on a thread | first 25 | `/v1/reddit/post-comments` | top-level batch plus a `next_cursors` entry per collapsed branch, with `depth` and `parent_fullname` |
| A user's comments | no | `/v1/reddit/user-comments` | 25 comments for u/nasa plus `next_cursor`, in 1.7 s |
| Comment search | posts only | `/v1/reddit/search?type=comments` | 10 comments for "web scraping" |
| Many posts at once | 50 in 6.3 s, paged for you | `/v1/reddit/subreddit-posts` | one Reddit page (about 24 posts) per call, plus `next_cursor` |

A thread call returns one batch of the comment tree. Each entry of `next_cursors` is a collapsed branch: send it back as `cursor` to load that branch, one call each. `truncated_threads` counts branches Reddit only links to by permalink. Comments come back flat in thread order, and `depth` plus `parent_fullname` let you rebuild the tree. The response is trimmed:

```bash
curl -H "x-api-key: $TOOLZERHUB_API_KEY" \
  "https://api.toolzerhub.com/v1/reddit/post-comments?subreddit=Python&post_id=1x1t161"
```

```json
{
  "data": {
    "total_comments": 70,
    "count": 25,
    "next_cursors": ["commenttree:..."],
    "end_of_tree": false,
    "truncated_threads": 2,
    "comments": [
      { "id": "pewn5rx", "parent_fullname": null, "depth": 0, "score": 60, "body": "...", "created_at": "2026-10-09T19:04:34.899000+0000" }
    ]
  }
}
```

The real response carries 17 fields per comment, including the author and permalink. For comment search and a CSV script, see our [Reddit search API guide](https://toolzerhub.com/blog/reddit-search-api). There are nine `/v1/reddit` endpoints, from subreddit info to user profiles; for a community's size now that member counts are gone, see [subreddit member count](https://toolzerhub.com/blog/subreddit-member-count).

## What it costs

Every `/v1/reddit` call costs 1 credit and returns one Reddit page, so 1,000 subreddit posts take about 42 calls, or 42 credits. You get 100 free credits a month; $19 buys 10,000 credits that never expire, and [plans for higher volume](https://toolzerhub.com/pricing) cover more subreddits. [Get a free key](https://app.toolzerhub.com/signup) and run the first request.

The official Data API route and its price are covered in [Reddit API pricing](https://toolzerhub.com/blog/reddit-api-pricing). For the same kind of script on another platform, see our [Instagram scraper in Python](https://toolzerhub.com/blog/instagram-scraper-python).

We are not affiliated with Reddit, Inc.
