使用Wunderground API进行Python抓取的麻烦

时间:2014-09-10 12:36:04

标签: python json web-scraping

我正在使用Wunderground API批量搜索历史天气数据。我的代码适用于1970年之前的日期,但之后它返回以下错误。怎么可能出错?

historical_url = "http://api.wunderground.com/api/" + api_key + "/history_" + year + month + day + \
                "/q/" + state + "/" + city + ".json"

# Pull data from url for given location and date 
f = urllib2.urlopen(historical_url)

# Read the data into JSON object
json_string = f.read()

parsed_json = json.loads(json_string)

这是错误:

File "/home/svenkatesh/Weather/getdata.py", line 82, in getHistory
parsed_json = json.loads(json_string)
File "/apps/python27/lib/python2.7/json/__init__.py", line 338, in loads
return _default_decoder.decode(s)
File "/apps/python27/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/apps/python27/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 68: invalid start byte

0 个答案:

没有答案