Search code examples
pythonjsonapireddit

How do I see/get the Number of subreddits I downloaded using reddits API


>>> import requests
>>> from pprint import pprint 

>>> r = requests.get('http://www.reddit.com/reddits.json', headers= {'User-Agent': 'me'})
>>> data = r.json()
>>> pprint(data.keys())

This prints subreddits & im trying to figure out how much it prints out or if I can print out a certain number. Thanks !


Solution

  • import requests
    
    r = requests.get('http://www.reddit.com/reddits.json', headers= {'User-Agent': 'me'})
    data = r.json()
    
    print(len(data['data']['children']))
    

    The structure of the JSON is complicated, so I'm not entirely sure what you are trying to count, but ['data']['children'] appears to be the root of the subreddits.