使用json时,报以下错误:
import json
import requests
#1.请求json接口整体数据
response=requests.get("https://movie.douban.com/typerank?type_name=%E5%89%A7%E6%83%85&type=11&interval_id=100:90&action=")
#2.抽取想要的数据
py_data = json.loads(response.text)
JSONDecodeError Traceback (most recent call last)
<ipython-input-6-e7f1241d2486> in <module>
6
7 #2.抽取想要的数据
----> 8 py_data = json.loads(response.text)
9 print(py_data) #查看数据类型 字典类型
F:\Anaconda3\lib\json\__init__.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw)
346 parse_int is None and parse_float is None and
347 parse_constant is None and object_pairs_hook is None and not kw):
--> 348 return _default_decoder.decode(s)
349 if cls is None:
350 cls = JSONDecoder
F:\Anaconda3\lib\json\decoder.py in decode(self, s, _w)
335
336 """
--> 337 obj, end = self.raw_decode(s, idx=_w(s, 0).end())
338 end = _w(s, end).end()
339 if end != len(s):
F:\Anaconda3\lib\json\decoder.py in raw_decode(self, s, idx)
353 obj, end = self.scan_once(s, idx)
354 except StopIteration as err:
--> 355 raise JSONDecodeError("Expecting value", s, err.value) from None
356 return obj, end
JSONDecodeError: Expecting value: line 1 column 1 (char 0)
我最后的解决方案是:报错的原因是网址错误。刷新页面,将url重新粘贴过去,就对了。报错的原因是网址错误

2万+




被折叠的 条评论
为什么被折叠?



