码迷,mamicode.com
首页 > 编程语言 > 详细

Python Json获取天气预报

时间:2016-01-07 16:46:26      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

#!/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"]);

 

Python Json获取天气预报

标签:

原文地址:http://www.cnblogs.com/shuyu/p/5110139.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!