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']  

  • 相关阅读:
    nginx常用模块(三)
    Nmap脚本文件分析(AMQP协议为例)
    Nmap脚本引擎原理
    小型Basic编译器问题
    Nmap原理02
    基于Docker搭建GitLab服务器
    关于Telnet使用
    Linux系统搭建GitLab---阿里云Centos7搭建Gitlab踩坑
    Vi文本编辑器
    Linux 奇技淫巧之常用指令
  • 原文地址:https://www.cnblogs.com/weikunzz/p/6710529.html
Copyright © 2011-2022 走看看