1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| import urllib.request import urllib.parse import requests from pprint import pprint
url = 'https://api.douban.com/v2/book/search?q=%22%E7%99%BD%E5%A4%9C%E8%A1%8C%22&count=1&apikey=0df993c66c0c636e29ecbb5344252a4a'
def useUrllib(): print("useUrllib") f = urllib.request.urlopen(url) print(f.read().decode('utf-8'))
def useRequests(): print("useRequests") r = requests.get(url) jsonResult = r.json(); pprint(jsonResult)
if __name__ == "__main__": useRequests()
|