reddit-scraper
v0.4.0
Published
Reddit scraper for fetching posts and comments via the official API with automatic caching
Maintainers
Readme
Reddit Scraper
Reddit Scraper for fetching posts and comments via the official API.
- Built with zero-dependencies
- Available as CLI
- Available as TypeScript library
- Automatically caches and fetches only changed posts and comments
Installation
Global installation (recommended for CLI usage)
npm install -g reddit-scraperUsing npx (no installation required)
npx reddit-scraper --subreddit improv --verboseAs a library in your project
npm install reddit-scraperUsage
CLI
After global installation:
reddit-scraper --subreddit improv --verboseOr using npx:
npx reddit-scraper --subreddit improv --max-posts 50 --max-days 30CLI Options
Required:
-s, --subreddit <name> Subreddit name (without r/)
Options:
-p, --max-posts <number> Maximum number of posts to scrape (default: 100)
-d, --max-days <number> Number of days back to scrape (default: 7)
-v, --verbose Enable verbose/debug logging
-h, --help Show this help messageAs a library
import { scrapeSubreddit } from 'reddit-scraper';
await scrapeSubreddit({
subreddit: 'improv',
maxPostCount: 100,
maxPostAge: Math.floor(Date.now() / 1000) - (7 * 24 * 60 * 60) // 7 days ago
});Developers: Getting started
npm installRun the scraper in development mode:
npm run dev -- --subreddit improv --verboseBuild the project:
npm run buildConfiguration
Create a .env file with your Reddit API credentials:
REDDIT_CLIENT_ID=your_client_id
REDDIT_SECRET=your_secretSee "Create Reddit App" section below for instructions on obtaining credentials.
API documentation
- This project is heavily using https://www.reddit.com/dev/api#GET_new
- See Official API Definition
Create Reddit App
- Created a Reddit app with your account in https://old.reddit.com/prefs/apps/
- Copy client id and secret into the
.envfile
