For a project, I need to extract multiple posts from specific subreddits using PRAW. The approach that I want to do requires having posts from multiple months
With the below, I only got all the mixed dates...
#! usr/bin/env python3
import praw
import pandas as pd
import datetime as dt
reddit = praw.Reddit(client_id='PERSONAL_USE_SCRIPT_14_CHARS', \
client_secret='SECRET_KEY_27_CHARS ', \
user_agent='YOUR_APP_NAME', \
username='YOUR_REDDIT_USER_NAME', \
password='YOUR_REDDIT_LOGIN_PASSWORD')
subreddit = reddit.subreddit('myTopic')
for submission in subreddit.top(limit=1):
print(submission.title, submission.id)
Now we are ready to start scraping the data from the Reddit API. We will iterate through our top_subreddit object and append the information to our dictionary.
for submission in top_subreddit:
topics_dict["title"].append(submission.title)
topics_dict["score"].append(submission.score)
topics_dict["id"].append(submission.id)
topics_dict["url"].append(submission.url)
topics_dict["comms_num"].append(submission.num_comments)
topics_dict["created"].append(submission.created)
topics_dict["body"].append(submission.selftext)
Exporting a CSV
topics_data.to_csv('dataFromReddit.csv', index=False)
As I mentioned above I would like to extract the data by month.
I checked in the official doc, there is something that I can use, but I don't know how to implement it on my code.