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

相关文章

对python3.4 字符串转16进制的实例详解

如下所示: def str_to_hex(s):     s = s.split(' ')     send_buf =...

在python win系统下 打开TXT文件的实例

如下所示: fr=open("E:\Python\Test\datingTestSet.txt") arrayOLines = fr.readlines() open:打开文件 r...

详解python函数的闭包问题(内部函数与外部函数详述)

python函数的闭包问题(内嵌函数) >>> def func1(): ... print ('func1 running...') ... def fu...

详解Python在使用JSON时需要注意的编码问题

详解Python在使用JSON时需要注意的编码问题

写这篇文章的缘由是我使用 reqeusts 库请求接口的时候, 直接使用请求参数里的 json 字段发送数据, 但是服务器无法识别我发送的数据, 排查了好久才知道 requests 内部...

Python中的jquery PyQuery库使用小结

pyquery库是jQuery的Python实现,可以用于解析HTML网页内容,使用方法:复制代码 代码如下:from pyquery import PyQuery as pq1、可加载...