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