使用web API
import requests url = 'https://api.github.com/search/repositories?q=language:python&sort=stars' headers = {'Accept':'application/vnd.github.v3+json'} r=requests.get(url,headers=headers) print(f'Status code:{r.status_code}') response_dict = r.json() print(response_dict.keys()) repo_dicts = response_dict['items'] print(f'\nSelected information about each respository:') for repo_dict in repo_dicts: print(f"\nName:{repo_dict['name']}") print(f"Owner:{repo_dict['owner']['login']}") print(f"Stars:{repo_dict['stargazers_count']}") print(f"Repository:{repo_dict['html_url']}") print(f"Description:{repo_dict['description']}")
api是什么:
api是2个主体间的接口,类似与古代的信使,让双方交换信息
#意外发现
https://github.com/jackfrued/Python-100-Days 非常好的教程
标签:github,api,chap17,repo,API,dict,使用,print,response From: https://www.cnblogs.com/hbdxlzy/p/17285825.html