Last active
January 18, 2020 17:05
-
-
Save gavin19/7873770 to your computer and use it in GitHub Desktop.
Scrape user names from reddit thread
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import praw | |
# PRAW ident | |
ua = '/u/someone for /r/somesub' | |
r = praw.Reddit(user_agent=ua) | |
# Fetch thread contents where submission_id is found at | |
# reddit.com/r/somesub/comments/submission_id/the_post_title_yay | |
thread = r.get_submission(submission_id='xxxxxx') | |
thread.replace_more_comments(limit=None, threshold=0) | |
flat_list = praw.helpers.flatten_tree(thread.comments) | |
# Ignore deleted comments and dupes and write out user names | |
authors = [] | |
with open('thread.csv', 'w') as f: | |
for thing in flat_list: | |
if thing.author is not None and thing.author.name not in authors: | |
authors.append(thing.author.name) | |
f.write(thing.author.name) | |
f.write('\n') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment