Skip to main content

RedditMiner: Subreddit Image Scraper

Quick Start

  1. Install RedditMiner from PyPI:

    pip install redditminer
    
  2. Export your Reddit cookies (see below) and save as cookies.txt in your working directory.

  3. Run example commands:

    • Scrape 200 top posts and save as JSON:

      redditminer --subreddit funny --limit 200 --sort top
      
    • Scrape only image URLs (TXT file):

      redditminer --subreddit funny --output-mode image_url
      
    • Scrape posts with top-level comments included (JSON):

      redditminer --subreddit funny --output-mode post --with-comment
      
    • Scrape and immediately download all images:

      redditminer --subreddit funny --output-mode image_url --download-images
      
    • Customize the download directory and parallelism:

      redditminer --subreddit funny --output-mode image_url --download-images --output-dir my_images --max-workers 16
      

Note: Make sure you have cookies.txt in your current directory for authentication. If you encounter rate limiting, RedditMiner will automatically slow down and retry.

RedditMiner Arctic Logo

RedditMiner: Subreddit Image Scraper

RedditMiner is a lightweight, open-source Python tool for scraping image and gallery URLs from any public or private subreddit using your browser session cookies. No Reddit API credentials required—works even for NSFW and restricted subreddits.

Features

  • Cookie Authentication: Uses your browser session cookies for seamless access.
  • Image & Gallery Support: Extracts direct image links and all images from Reddit galleries.
  • Deep Pagination: Efficiently fetches large numbers of posts using Reddit's pagination.
  • Command-Line Interface: Specify the subreddit and options directly via command line.

Installation

  1. Clone the repository

    git clone https://github.com/MisbahKhan0009/RedditMiner.git
    cd RedditMiner
    
  2. Install dependencies

    pip install requests
    
  3. Export your Reddit cookies

    • Log into Reddit in your browser.
    • Use a browser extension like "EditThisCookie" or "Get cookies.txt" to export your cookies for reddit.com.
    • Save the exported file as cookies.txt in the project root directory.

You can install RedditMiner directly from PyPI:

pip install redditminer

Or, for development, clone the repository and install dependencies:

git clone https://github.com/MisbahKhan0009/RedditMiner.git
cd RedditMiner
pip install -e .

Export your Reddit cookies

  • Log into Reddit in your browser.
  • Use a browser extension like "EditThisCookie" or "Get cookies.txt" to export your cookies for reddit.com.
  • Save the exported file as cookies.txt in your working directory.

Usage

Run the scraper with your desired subreddit:

python main.py --subreddit EarthPorn

After installation, you can use RedditMiner from the command line:

redditminer --subreddit EarthPorn

Or, if running from source:

python main.py --subreddit EarthPorn

Optional arguments

  • post (default): Full post data (JSON)
  • image_url: Only image URLs (from both image_url and gallery_images fields, TXT file)
  • post_with_comments: Full post data with comments (JSON, same as post if --with-comment is not set)

Rate Limiting: If Reddit returns a 429 (Too Many Requests) error, the scraper will automatically slow down and retry after 60 seconds. This helps avoid being blocked by Reddit's rate limits. For best results, avoid running multiple scrapes in parallel and consider using a fresh set of cookies if you encounter repeated rate limiting.

Command-line options

  • --subreddit : Subreddit name to scrape (required)
  • --limit : Number of posts to scrape (default: 100)
  • --sort : Sort order (new, hot, top, etc.; default: new)
  • --output-mode : Output format. Options:
    • post (default): Full post data (JSON)
    • image_url: Only image URLs (from both image_url and gallery_images fields, TXT file)
    • post_with_comments: Full post data with comments (JSON, same as post if --with-comment is not set)
  • --with-comment : Include top-level comments for each post (JSON output modes only). Comments from "AutoModerator" are automatically skipped.
  • --download-images : Download all found images
  • --output-dir : Directory to save images (default: images)
  • --max-workers : Number of parallel downloads (default: 8)

Rate Limiting: If Reddit returns a 429 (Too Many Requests) error, RedditMiner will automatically slow down and retry after 60 seconds. For best results, avoid running multiple scrapes in parallel and consider using a fresh set of cookies if you encounter repeated rate limiting.

Examples:

Scrape 200 top posts and save as JSON:

python main.py --subreddit funny --limit 200 --sort top

Scrape only image URLs (TXT file):

python main.py --subreddit funny --output-mode image_url

Scrape posts with top-level comments included (JSON):

python main.py --subreddit funny --output-mode post --with-comment

Each post in the output JSON will have a comments field containing a list of top-level comments (author, body, score, created_utc). Comments from "AutoModerator" are excluded.

Scrape and immediately download all images:

python main.py --subreddit funny --output-mode image_url --download-images

You can customize the download directory and parallelism:

python main.py --subreddit funny --output-mode image_url --download-images --output-dir my_images --max-workers 16

Examples:

Scrape 200 top posts and save as JSON:

redditminer --subreddit funny --limit 200 --sort top

Scrape only image URLs (TXT file):

redditminer --subreddit funny --output-mode image_url

Scrape posts with top-level comments included (JSON):

redditminer --subreddit funny --output-mode post --with-comment

Each post in the output JSON will have a comments field containing a list of top-level comments (author, body, score, created_utc). Comments from "AutoModerator" are excluded.

Scrape and immediately download all images:

redditminer --subreddit funny --output-mode image_url --download-images

You can customize the download directory and parallelism:

redditminer --subreddit funny --output-mode image_url --download-images --output-dir my_images --max-workers 16

Downloaded images are automatically organized by subreddit:

  • For example, images from r/EarthPorn will be saved in images/EarthPorn/ by default.
  • If you specify a custom output directory, images will be saved in <output-dir>/<subreddit>/.

Results are saved as:

  • JSON: output/images_[subreddit]_[timestamp].json
  • TXT (image URLs): output/images_[subreddit]_[timestamp].txt
  • Downloaded images: in images/<subreddit>/ (or <output-dir>/<subreddit>/ if specified)

Project Structure

RedditMiner/
│
├── redditminer/
│   ├── __init__.py
│   └── scraper.py         # Core scraping logic and RedditImageScraper class
│
├── main.py                # Command-line entry point
├── cookies.txt            # Your exported Reddit cookies
├── README.md
└── ...

Contributing

Contributions are welcome! Please open issues or submit pull requests for new features, bug fixes, or improvements.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Disclaimer

This tool is intended for personal and educational use. Please respect Reddit's Terms of Service and do not use this tool for spamming or violating site rules.

Metadata

Release files for RedditMiner 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for RedditMiner 1.0.2
File Size Uploaded
redditminer-1.0.2.tar.gz 10.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for RedditMiner 1.0.2
File Interpreter ABI Platform
redditminer-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 17.3 kB

Release files / redditminer-1.0.2.tar.gz

Download URL redditminer-1.0.2.tar.gz
Size 10.2 kB
Tags Source
SHA-256 checksum
How to use checksums
ed84ccdee618cc3981710d10d24c0a01a4a48db01943df8335919d646fc371a1
BLAKE2b-256 checksum
How to use checksums
eec03ad2ebf9ff5f8ee8d1e848e163b087aea9a4be30d4eefe1c4e87afac7d80
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release files / redditminer-1.0.2-py3-none-any.whl

Download URL redditminer-1.0.2-py3-none-any.whl
Size 7.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d1476250fd6e58f346ab964b98cf4d3d6b7cd17091c08e682e13f10579c762f
BLAKE2b-256 checksum
How to use checksums
52de1389fd2757520cb87915c9fe12a2a64b7392d3671d807c36c477a6da3ec0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page