Skip to content

Instantly share code, notes, and snippets.

@json-m json-m/
Created Dec 13, 2018

What would you like to do?
top 5 posts for /r/space
import requests
import json
count = 0
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/537.36'
r = requests.get('', headers=headers)
posts = json.loads(r.text)
print('--- /r/space top posts')
for post in posts['data']['children']:
print('[%s] %s' % (post['data']['score'], post['data']['title']))
print('URL: ' + post['data']['url'])
print('Comments: ' + '' + post['data']['permalink'])
count += 1
if count > 4:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.