1
votes

I am trying to obtain the top 10 posts from the subreddit Bitcoin using the praw wrapper but I get an empty list:

import praw

reddit = praw.Reddit(client_id = 'XXX',
                    client_secret = 'XXX',
                    username = 'XXX',
                    password = 'XXXX',
                    user_agent = 'XXXXX')

appended_data = []

subreddit = reddit.subreddit('bitcoin')  

top_python = subreddit.top(limit=10)     
for submission in top_python:
    if not submission.stickied:
        appended_data.append(submission.selftext)



appended_data

and I obtain the following empty list:

Out[105]: ['', '', '', '', '', '', '', '', '', '']

Any idea why?

Thanks

2

2 Answers

1
votes

Your script is correct, but the issue is that each of the top ten posts right now are all links.

So for instance, if I change appended_data.append(submission.selftext) to appended_data.append(submission.url) I get

['https://wikileaks.org/ciav7p1/',
 'http://i.imgur.com/TKiAJWX.gifv',
 'https://i.redd.it/nsokakmrn69z.jpg',
 'https://i.redd.it/djb8i3hoh3zy.jpg',
 'https://i.redd.it/7dvqdd5lbmiz.jpg',
 'https://i.redd.it/4p4r1q4zqvfz.jpg',
 'https://twitter.com/snowden/status/679692055271096321',
 'https://i.redd.it/f4dmhdwzexvy.jpg',
 'https://i.redd.it/giqzirlwg7az.jpg',
 'https://i.redd.it/rkwou70jut8z.jpg']

Edit: My bad, didn't see you already answered this

0
votes

The problem is that the top 10 posts are not necessarily textual. Therefore it retrieves an empty list.