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实现K最近邻算法

KNN核心算法函数,具体内容如下 #! /usr/bin/env python3 # -*- coding: utf-8 -*- # fileName : KNNdistance.p...

Python 在字符串中加入变量的实例讲解

有时候,我们需要在字符串中加入相应的变量,以下提供了几种字符串加入变量的方法: 1、+ 连字符 name = 'zhangsan' print('my name is '+name...

python如何保证输入键入数字的方法

要求:python写一个要求用户输入数字,如果不是数字就一直循环要求输入,直到输入数字为止的代码 错误打开方式: while True: ten=input('Enter a n...

Python实现购物车购物小程序

Python实现购物车购物小程序

概要 按理说,我们入门的第一个小程序都应该是Hello World。因为比较简单,我这也就不做过多的演示 了。 下面是我写的一个小程序。主要用于练习Python的基本语法,以及入门。...

kafka-python批量发送数据的实例

如下所示: from kafka import KafkaClient from kafka.producer import SimpleProducer def send_...