>>718442646
Method 1: Using Reddit API (Recommended)
Step-by-step:
Create a Reddit app:
Go to
https://www.reddit.com/prefs/apps
Click βCreate Appβ
Choose βscriptβ
Note down the client_id, client_secret, and user_agent
Install PRAW (Python Reddit API Wrapper):
pip install praw
Python Script to Scrape GIFs:
import praw
import requests
import os
reddit = praw.Reddit(
client_id="YOUR_CLIENT_ID",
client_secret="YOUR_CLIENT_SECRET",
user_agent="YOUR_USER_AGENT"
)
subreddit = reddit.subreddit("gifs") # or any subreddit of interest
posts = subreddit.hot(limit=50) # limit can be changed
save_folder = "downloaded_gifs"
os.makedirs(save_folder, exist_ok=True)
for post in posts:
if post.url.endswith(('.gif', '.gifv', '.mp4')):
file_name = post.url.split('/')[-1]
file_path = os.path.join(save_folder, file_name)
# Convert gifv to gif if needed
url = post.url.replace('.gifv', '.mp4')
try:
r = requests.get(url)
with open(file_path, 'wb') as f:
f.write(r.content)
print(f"Downloaded: {file_name}")
except Exception as e:
print(f"Failed to download {url}: {e}")
Method 2: Web scraping (Less reliable)
Reddit uses dynamic content and embeds media from other sources like Imgur, Gfycat, or Reddit-hosted video/CDN, which makes direct scraping difficult and brittle. It's often better to use an API or access third-party scraper-friendly mirrors.
Important Notes:
Respect Redditβs API rules
: donβt spam requests, and include a meaningful user_agent.
Always check the terms of service and fair use guidelines when scraping or downloading content.
Many GIFs on Reddit are actually MP4 videos for compression reasons (especially .gifv or .mp4 formats) β most modern browsers auto-play them as GIFs.