chap17使用API
使用web API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | 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 非常好的教程

本文作者:月海与游梦人
本文链接:https://www.cnblogs.com/hbdxlzy/p/17285825.html
版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步