python实例3-天气小模块

调用中国天气的一小段代码,抓取
#! /usr/bin/python  
# coding = utf-8  
  
# ToDo: get weather info from weather.com.cn  
# Author: Steven  
# Date: 2017/01/11  
  
import urllib2  
import json  
  
# get weather html and parse to json  
weatherHtml = urllib2.urlopen('http://m.weather.com.cn/data/101010100.html').read()  
weatherJSON = json.JSONDecoder().decode(weatherHtml)  
weatherInfo = weatherJSON['weatherinfo']  
  
# print weather info  
print '城市:\t', weatherInfo['city']  
print '时间:\t', weatherInfo['date_y']  
print '24小时天气:'  
print '温度:\t', weatherInfo['temp1']  
print '天气:\t', weatherInfo['weather1']  
print '风速:\t', weatherInfo['wind1']  
print '紫外线:\t', weatherInfo['index_uv']  
print '穿衣指数:\t', weatherInfo['index_d']  
print '48小时天气:'  
print '温度:\t', weatherInfo['temp2']  
print '天气:\t', weatherInfo['weather2']  
print '风速:\t', weatherInfo['wind2']  
print '紫外线:\t', weatherInfo['index48_uv']  
print '穿衣指数:\t', weatherInfo['index48_d']  
print '72小时天气:'  
print '温度:\t', weatherInfo['temp3']  
print '天气:\t', weatherInfo['weather3']  
print '风速:\t', weatherInfo['wind3']  

    原文作者:沐阳zz
    原文地址: https://blog.csdn.net/qq_33932782/article/details/54353245
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞