王锋 2015年12月02日 星期三 16:22 | 1163次浏览 | 0条评论
sfaasdf
# -*- coding: utf-8 -*-
import sys, urllib, urllib2, json
url = 'http://apis.baidu.com/apistore/weatherservice/weather?citypinyin=beijing'
req = urllib2.Request(url)
req.add_header("apikey", "ec1c4e765803f8a8862620fb66dac5c8")
resp = urllib2.urlopen(req)
content = resp.read()
if(content):
cs = json.loads(content)
if cs['errMsg']=="success":
wc=cs["retData"]
city = wc['city']
date = wc['date']
time = wc['time']
weather = wc['weather']
contents = city+date+u"天气"+weather
print contents
Zeuux © 2024
京ICP备05028076号
暂时没有评论