python - 如何使用python脚本通过API从网上下载JSON
问题描述
我是蟒蛇的新手。谁能告诉我如何从 python 中的给定 API 下载 JSON 文件,然后使用 mako 或 jinja 保存为 HTML?
- 使用python脚本通过API从网上下载JSON。
解决方案
您使用 requests 模块通过以下代码获取 json
import requests
url = "http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b6907d289e10d714a6e88b30761fae22"
res = requests.get(url)
if res.ok:
res.json()
有关其他资源,您可以点击此链接
推荐阅读
- sql - 根据条件插入表值的每一列
- excel - Visual Studio 说 -> Imports 'Microsoft.Office.Interop.Excel' 不包含任何公共成员或找不到
- lua - 使用 Lua 返回所需数据的问题
- raku - 在 Raku 中,不能从同一文件中定义的类继承方法特征
- xamarin.ios - 条带终端连接令牌已被兑换
- android - 在通过导航组件添加到动作的动画完成之前,防止单击视图
- python - 类型错误字符串索引必须是整数,而不是 str
- python - Django:取消订单时无法调整库存
- jboss - 如何在 Jhipster 生成的项目中为 Keycloak 启用 https?
- ios - 如何检测 UICollectionViewCell 的中点何时超出 UICollectionView 的框架?