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对比C语言的编程思想差异

通过实例浅析Python对比C语言的编程思想差异

我一直使用 Python,用它处理各种数据科学项目。 Python 以易用闻名。有编码经验者学习数天就能上手(或有效使用它)。 听起来很不错,不过,如果你既用 Python,同时也是用其...

Python3中的2to3转换工具使用示例

python3与python2的还是有诸多的不同,比如说在2中: 复制代码 代码如下: print "Hello,World!"  raw_input()  在...

Python 反转字符串(reverse)的方法小结

前段时间看到letcode上的元音字母字符串反转的题目,今天来研究一下字符串反转的内容。主要有三种方法: 1.切片法(最简洁的一种) #切片法 def reverse1(): s=...

Python字符串匹配之6种方法的使用详解

1. re.match 尝试从字符串的起始位置匹配一个模式,如果不是起始位置匹配成功的话,match()就返回none。 import re line="this hdr-biz 1...

Python将图片批量从png格式转换至WebP格式

Python将图片批量从png格式转换至WebP格式

实现效果 将位于/img目录下的1000张.png图片,转换成.webp格式,并存放于img_webp文件夹内。 源图片目录 目标图片目录 关于批量生成1000张图片,可以参考这篇文...