先去YY天气注册一个账号,然后就能用API了
http://www.yytianqi.com/
# encoding=utf-8
import urllib.request
import json
import collections
cityid = ‘http://api.yytianqi.com/observe?key=API的key&city=城市ID‘
response = urllib.request.urlopen(cityid) //打开网页
html = response.read().decode(‘utf-8‘)//解码为utf-8
info = json.loads(html, object_pairs_hook=collections.OrderedDict)//把json转成python
print(info)
时间: 2024-11-04 02:03:36