通过requests请求api接口,返回的数据为一串字典,可使用字典的方式进行操作
import requests url = 'https://api.github.com/search/repositories?q=language:python&sort=stars' r = requests.get(url) print('status code:',r.status_code) print(r.json()) #返回的值包含空格 print(r.content) con = r.json() #返回一个字典,然后就有字典的属性,keys,values,items print(con.keys()) print(con.items()) print(con['items']) print(len(con)) print(con['total_count']) for key in con.keys(): print(key)