第17 章调用API
1.调用API
import requests import time #执行API url="https://api.github.com/search/repositories?q=language:python&sort=stars" r=requests.get(url) print("Status code:",r.status_code) #将API响应存储在一个变量中 response_dict=r.json() print("Total repositories:,",response_dict['total_count']) # 探索仓库的信息 response_dicts=response_dict['items'] print("Repositories returned:",len(response_dicts)) # 研究第一个仓库 repo_dict=response_dicts[0] print("\nKeys:",len(repo_dict)) for key in sorted(repo_dict.keys()): print(key)