首页 全国天气预报 全国天气预报示例代码 获取城市[Python]

获取城市示例代码[Python]

作者:liuxiaojie 阅读数:2950 上传时间:2016-03-10

获取城市

#!/usr/bin/python
# encoding:utf-8

import urllib2, json, urllib


#  2、获取城市



data = {}
data["appkey"] = "your_appkey_here"

url_values = urllib.urlencode(data)
url = "https://api.jisuapi.com/weather/city" + "?" + url_values
result = urllib2.urlopen(url)
jsonarr = json.loads(result.read())

if jsonarr["status"] != u"0":
    print jsonarr["msg"]
    exit()
result = jsonarr["result"]
for val in result:
    print val["cityid"],val["parentid"],val["citycode"],val["city"]