- 帖子
- 3
- 精华
- 0
- 积分
- 20
- 阅读权限
- 10
- 注册时间
- 2013-8-15
- 最后登录
- 2013-9-15
|
crossin先生 发表于 2013-8-15 23:33
那种乱码?把代码和程序错误都发上来看看
代码就是贴的你写的:
# -*- coding: cp936 -*-
import urllib2
url1 = 'http://m.weather.com.cn/data5/city.xml'
content1 = urllib2.urlopen(url1).read()
provinces = content1.split(',')
result = 'city = {\n'
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(',')
for c in cities:
c_code = c.split('|')[0]
url3 = url % c_code
content3 = urllib2.urlopen(url3).read()
districts = content3.split(',')
for d in districts:
d_pair = d.split('|')
d_code = d_pair[0]
name = d_pair[1]
url4 = url % d_code
content4 = urllib2.urlopen(url4).read()
code = content4.split('|')[1]
line = " '%s': '%s',\n" % (name, code)
result += line
print name + ':' + code
result += '}'
f = file('/home/crossin/Desktop/city.py', 'w')
f.write(result)
f.close()
然后乱码是这样:
鍏拌タ:101050507
闈掑唸:101050508
搴嗗畨:101050509
缁ユ1:101050510
榛戞渤:101050601
瀚╂睙:101050602
瀛欏惔:101050603
閫婂厠:101050604
浜斿ぇ杩炴睜:101050605
鍖楀畨:101050606
澶у叴瀹夊箔:101050701
濉旀渤:101050702
婕犳渤:101050703
鍛肩帥:101050704
鍛间腑:101050705
鏂版灄:101050706
浼婃槬:101050801
乌伊岭:101050802
浜旇惀:101050803
閾佸姏:101050804
鍢夎崼:101050805
澶у簡:101050901
鏋楃敻:101050902
鑲囧窞:101050903
鑲囨簮:101050904
鍕冨埄:101051002
楦¤タ:101051101
铏庢灄:101051102
瀵嗗北:101051103
楦′笢:101051104
楣ゅ矖:101051201
缁ユ花:101051202
钀濆寳:101051203
双鸭山:101051301
闆嗚搐:101051302
瀹濇竻:101051303
渚ユ渤:101051304
闀挎槬:101060101
鍐滃畨:101060102
寰锋儬:101060103
涔濆彴:101060104
姒嗘爲:101060105
鍙岄槼:101060106
鍚夋灄:101060201
鑸掑叞:101060202
姘稿悏:101060203
铔熸渤:101060204
纾愮煶:101060205
妗︾敻:101060206
寤跺悏:101060301
鏁﹀寲:101060302
瀹夊浘:101060303
汪清:101060304
鍜岄緳:101060305
榫欎簳:101060307
鐝叉槬:101060308
鍥句滑:101060309
|
|