zoukankan      html  css  js  c++  java
  • 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 '城市:	', weatherInfo['city']  
    print '时间:	', weatherInfo['date_y']  
    print '24小时天气:'  
    print '温度:	', weatherInfo['temp1']  
    print '天气:	', weatherInfo['weather1']  
    print '风速:	', weatherInfo['wind1']  
    print '紫外线:	', weatherInfo['index_uv']  
    print '穿衣指数:	', weatherInfo['index_d']  
    print '48小时天气:'  
    print '温度:	', weatherInfo['temp2']  
    print '天气:	', weatherInfo['weather2']  
    print '风速:	', weatherInfo['wind2']  
    print '紫外线:	', weatherInfo['index48_uv']  
    print '穿衣指数:	', weatherInfo['index48_d']  
    print '72小时天气:'  
    print '温度:	', weatherInfo['temp3']  
    print '天气:	', weatherInfo['weather3']  
    print '风速:	', weatherInfo['wind3']  

  • 相关阅读:
    1203 有穷自动机
    1111 评论
    C语言文法 改
    用户调研
    阅读《构建之法》 第8 第9 第10章
    sprint冲刺(第二天)
    sprint初步计划(第一天)
    作业6 团队项目之需求
    作业5 四则运算 测试与封装 5.1 5.2
    作业5 四则运算 测试与封装 5.1
  • 原文地址:https://www.cnblogs.com/weikunzz/p/6710529.html
Copyright © 2011-2022 走看看