Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using praw, how can I iterate over all of a user's comments? [closed]

I'm just wondering if there's a simple enough way to iterate over all comments made by a particular user (I want to check for a particular phrase). Any help is appreciated :)

like image 643
user3585259 Avatar asked Jan 10 '23 17:01

user3585259


1 Answers

You can't get all comments, if the user has more than 1,000 comments. It is a limitation of the reddit API. However, the code below will get (and print the body) of all comments made by a user.

import praw

r = praw.Reddit('Your unique user agent')
user = r.get_redditor('REDDITOR-USER-HANDLE')
for comment in user.get_comments(limit=None):
    print comment.body

A coupe notes:

  • Remember to have a unique user agent
  • REDDITOR-USER-HANDLE is the user name of the user you are looking at
like image 187
Andy Avatar answered Jan 17 '23 14:01

Andy