Here’s a simple Python script that scrapes Reddit posts using the praw
(Python Reddit API Wrapper) library. This script fetches the top posts from a specified subreddit.
✅ Prerequisites:
-
Install the
praw
library:
-
Create a Reddit app to get your API credentials:
Go to https://www.reddit.com/prefs/apps → click “create another app” → choose script → fill in name, redirect URI (can behttp://localhost
), and note down:-
Client ID
-
Client Secret
-
User Agent (custom string, e.g.,
MyRedditScraper/0.1
)
-
🔧 Reddit Post Scraper Script
🔄 Customization Options:
-
To scrape from hot, new, or rising:
Replacesubreddit.top(...)
with:-
subreddit.hot(limit=post_limit)
-
subreddit.new(limit=post_limit)
-
subreddit.rising(limit=post_limit)
-
-
To output to a CSV or JSON file, let me know — I can add that part.
Let me know if you want this adapted for multiple subreddits, date filtering, or keyword search.
Leave a Reply