1

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.

Search from official doc

Lorenzo Castagno
  • 528
  • 1
  • 10
  • 27
  • 1
    The Reddit API doesn't let you get posts from arbitrary dates (though it used to). You can, however, use third-party services to accomplish this. See [this answer](https://stackoverflow.com/a/54046328/8033766) for more information. – jarhill0 Apr 17 '20 at 19:59

0 Answers0