源代码
# -*- coding: utf-8 -*-
import urllib2
import json
from city import city
cityname=raw_input('你想查询哪个城市天气?\n')
citycode=city.get(cityname)
print citycode
if citycode:
url=('http://www.weather.com.cn/weather1d/%s.shtml#input'%citycode)
content=urllib2.urlopen(url).read()
print content
else:
print'no this city'
运行结果:
你想查询哪个城市天气?
南京
None
no this city