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实现一个简单的MySQL类

本文实例讲述了Python实现一个简单的MySQL类。分享给大家供大家参考。 具体实现方法如下: 复制代码 代码如下:#!/usr/bin/env python # -*- coding...

pymysql 开启调试模式的实现

pymysql 开启调试模式的实现

今天在排查线上一个奇怪的数据库连接问题,所以打开了 pymysql 的源码在阅读,发现 pymysql 在其 connections 模块里内置了一个 DEBUG 变量用于控制是否开启调...

深入理解Django的中间件middleware

深入理解Django的中间件middleware

本文讲述的内容基于 Django 1.11 摘要 Django 中的中间件(middleware),是一个镶嵌到Django的request/response处理机制中的一个hooks框...

python并发编程之多进程、多线程、异步和协程详解

最近学习python并发,于是对多进程、多线程、异步和协程做了个总结。 一、多线程 多线程就是允许一个进程内存在多个控制权,以便让多个函数同时处于激活状态,从而让多个函数的操作同时运行...

python strip() 函数和 split() 函数的详解及实例

 python strip() 函数和 split() 函数的详解及实例 一直以来都分不清楚strip和split的功能,实际上strip是删除的意思;而split则是分割的意...