注意:这是Python 3,没有urllib2.此外,我还try 过使用json.加载(),我得到以下错误:
TypeError: can't use a string pattern on a bytes-like object
如果我使用json,就会出现这个错误.加载()并移除.从响应中读取()
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'])
不起作用...我不知道为什么.