Note: This is Python 3, there is no urllib2. Also, I've tried using json.loads(), and I get this error:
TypeError: can't use a string pattern on a bytes-like object
I get this error if I use json.loads() and remove the .read() from response:
TypeError: expected string or buffer
>
import urllib.request
import json
response = urllib.request.urlopen('http://www.reddit.com/r/all/top/.json').read()
jsonResponse = json.load(response)
for child in jsonResponse['data']['children']:
print (child['data']['title'])
Does not work... I have no idea why.
urllib2.urlopen
instead – Mispronouncehttp.client
: docs.python.org/3/library/http.client.html#examples – Bergmans