- 帖子
- 30
- 精华
- 0
- 积分
- 80
- 阅读权限
- 20
- 注册时间
- 2017-8-24
- 最后登录
- 2017-9-5
|
本帖最后由 blueheart 于 2017-8-24 19:57 编辑
- # -*- coding: UTF-8 -*-
- import urllib2
- url1 = 'http://m.weather.com.cn/data3/city.xml'
- content1 = urllib2.urlopen(url1).read()
- provinces = content1.split(',')
- print content1
- url = 'http://m.weather.com.cn/data3/city%s.xml'
- for p in provinces:
- p_code = p.split('|')[0]
- url2 = url % p_code
- content2 = urllib2.urlopen(url2).read()
- cities = content2.split(',')
- print content2.decode('utf-8')
- for c in cities[:3]:
- c_code = c.split('|')[0]
- url3 = url % c_code
- content3 = urllib2.urlopen(url3).read()
- districts = content3.split(',')
- print content3.decode('utf-8')
复制代码 |
|