导入包了,还是报错,小白向含泪大神求助!!!
import urllib2from cityCode import city
import json
location = raw_input('请输入你需要查询的城市名字:')
citycode=""
# 城市编码获取
try:
citycode =city
except:
print ("没找到")
url= "http://www.weather.com.cn/data/cityinfo/"+citycode+".html"#构造网址
# 发起查询
weather_json_string = urllib2.urlopen(url).read()
# 结果分析
weather = json.loads(weather_json_string)
print (weather)
# 结果打印
print (weather['weatherinfo']['city'])
print (weather['weatherinfo']['ptime'])
print (weather['weatherinfo']['cityid'])
print (weather['weatherinfo']['temp2'])
print (weather['weatherinfo']['temp1'])
print (weather['weatherinfo']['weather'])
报错信息:
Traceback (most recent call last):
File "C:/Users/CLARE/Desktop/tq.py", line 2, in <module>
import urllib2
File "D:\anaconda\lib\site-packages\urllib2.py", line 220
raise AttributeError, attr
^
SyntaxError: invalid syntax 你这是Python2还是Python3?
页:
[1]