python显示天气预报

yipeiwu_com6年前Python基础

复制代码 代码如下:

import urllib2
import json
import string
url ='http://m.weather.com.cn/data/101090502.html'
re = urllib2.urlopen(url).read()
we = json.loads(re)['weatherinfo']
print we['city'] , we['date_y'].center(30) ,   we['week']
print we['temp1'], we['weather1'].center(30),  we['wind1']
print we['temp2'], we['weather2'].center(30),  we['wind2']
print we['temp3'], we['weather3'].center(30),  we['wind3']
print we['temp4'], we['weather4'].center(30),  we['wind4']
print we['temp5'], we['weather5'].center(30),  we['wind5']
print we['temp6'], we['weather6'].center(30),  we['wind6']
print we['index48_d']
raw_input('plese input Enter to esc')

相关文章

Flask SQLAlchemy一对一,一对多的使用方法实践

Flask-SQLAlchemy安装和建表操作请参考这里。 复制代码 代码如下:# Role表class Role(db.Model):    id=db...

python定时利用QQ邮件发送天气预报的实例

python定时利用QQ邮件发送天气预报的实例

大致介绍 好久没有写博客了,正好今天有时间把前几天写的利用python定时发送QQ邮件记录一下 1、首先利用request库去请求数据,天气预报使用的是和风天气的API(www.hewe...

python 返回列表中某个值的索引方法

如下所示: list = [5,6,7,9,1,4,3,2,10] list.index(9) out:3 同时可以返回列表中最大值的索引list.index(max(lis...

Python简单日志处理类分享

简单的一个python日志处理类 复制代码 代码如下: #/usr/bin/python #coding=utf-8 import time,types class logsys: &n...

跟老齐学Python之大话题小函数(1)

开篇就要提到一个大的话题:编程范型。什么是编程范型?引用维基百科中的解释: 复制代码 代码如下: 编程范型或编程范式(英语:Programming paradigm),(范即模范之意,范...