首页 > 解决方案 > 如何使用python脚本通过API从网上下载JSON

问题描述

我是蟒蛇的新手。谁能告诉我如何从 python 中的给定 API 下载 JSON 文件,然后使用 mako 或 jinja 保存为 HTML?

  1. 使用python脚本通过API从网上下载JSON。

标签: pythonjsonmako

解决方案


您使用 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()

有关其他资源,您可以点击此链接


推荐阅读