您的位置:首页 > 编程语言 > Python开发

Python Json获取天气预报

2016-01-07 15:50 447 查看
#!/usr/bin/python
# -*- coding: UTF-8 -*-
import json
import smtplib
import urllib
from email.mime.text import MIMEText

def getHtml(url):
page = urllib.urlopen(url)
html = page.read()
return html.decode("utf-8")

str = getHtml("http://api.map.baidu.com/telematics/v3/weather?location=沈阳&output=json&ak=Dy2Zop7tjKlj2EZxwe88Hbjz")
_json = json.loads(str)["results"]
_json = _json[0]["weather_data"];

print("沈阳天气:".decode("utf-8"))
for i in range(0, 4):
print(_json[i]["date"] + " " + _json[i]["weather"] + " " + _json[i]["wind"] + " " + _json[i]["temperature"]);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: