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

相关文章

Python时间和字符串转换操作实例分析

本文实例讲述了Python时间和字符串转换操作。分享给大家供大家参考,具体如下: 例子: #!/usr/bin/python # -*- coding: UTF-8 -*- impo...

python求最大值,不使用内置函数的实现方法

利用python进行求解,求解的要求是不能使用python内部封装好的函数例如:max way1: def findmax(data,n): if n==1: return d...

python求解数组中两个字符串的最小距离

题目: 给定一个数组 strs,其中的数据都是字符串,给定两个字符串 str1,str2。如果这两个字符串都在 strs数组中,就返回它们之间的最小距离;如果其中任何一个不在里面,则返...

Python IDLE清空窗口的实例

使用Python IDLE时发现并没有清空当前窗口的快捷键,也没有像 clear 这样的命令,使用非常不便。 新建一个 ClearWindow.py脚本,源码如下: """ Cle...

Python解决抛小球问题 求小球下落经历的距离之和示例

本文实例讲述了Python解决抛小球问题 求小球下落经历的距离之和。分享给大家供大家参考,具体如下: 问题: 小东和三个朋友一起在楼上抛小球,他们站在楼房的不同层,假设小东站的楼层距离地...