Python, Requestsの使い方 | note.nkmk.me
天気予報 API(livedoor 天気互換)
weather_request.py
import requests
import json
def main():
url = "https://weather.tsukumijima.net/api/forecast/city/130010"
res = requests.get(url)
json_text = json.dumps(res.json())
with open("f.txt", "w", encoding="utf-8") as f:
f.write(json_text)
json_obj = json.loads(json_text) # ロード
print(json_obj)
# {'publicTime': '2020-12-12T17:00:00+09:00', 'publicTime_format': '2020/12/12 17:00:00', 'title': '東京都 東京 の天気', '
if __name__ == '__main__':
main()