调用中国天气的一小段代码,抓取
#! /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']  

相关文章:

  • 2021-08-18
  • 2022-01-31
  • 2022-12-23
  • 2021-11-18
  • 2021-10-12
  • 2021-09-19
  • 2021-04-19
  • 2022-02-12
猜你喜欢
  • 2021-11-18
  • 2021-06-14
  • 2021-05-29
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
相关资源
相似解决方案