- 帖子
- 6
- 精华
- 0
- 积分
- 53
- 阅读权限
- 20
- 注册时间
- 2017-9-13
- 最后登录
- 2017-12-12
|
# -*- coding: utf-8 -*-
import urllib2
import json
from city import city
'''
web = urllib2.urlopen('http://www.baidu.com')
content = web.read()
outhtml = file('content.html','w')
outhtml.write(content)
outhtml.close()
'''
cityname = raw_input('你想查哪个城市的天气?\n')
citycode = city.get(cityname) #city[cityname]
#print cityname,citycode
'''
citycode = city.get(cityname) #city[cityname]
print cityname,citycode
'''
if citycode:
url=('http://www.weather.com.cn/data/cityinfo/%s.html'%citycode)
content = urllib2.urlopen(url).read()
print content
以上是我的代码,返回结果如下(并没有返回天气的json信息,求指教,我用的pc):
>>> ================================ RESTART ================================
>>>
你想查哪个城市的天气?
南京
>>>
|
|