Comment Scrape Test


/ Published in: Python
Save to your folder(s)

Using this, I scrape all comments of a particular submission, and print them in a flat fashion. This is purely comment bodies, not usernames, karma, or any other meta data.


Copy this code and paste it in your HTML
  1. import time
  2. import praw
  3.  
  4. r = praw.Reddit('[REDACTED]')
  5. already_done = []
  6. submission = r.get_submission('http://www.reddit.com/r/learnprogramming/comments/362ark/how_are_reddit_bots_created/')
  7. submission.replace_more_comments(limit=30, threshold=10)
  8. flat_comments = praw.helpers.flatten_tree(submission.comments)
  9.  
  10. while True:
  11. for comment in flat_comments:
  12. f = open('comments.txt', 'a')
  13. f.write(comment.body + '\n' + '+--------------------------------------------------------------------------------------------------------------------------+' + '\n')

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.