爬虫时进行Response中的json数据提取,将返回内容转化为dic类型时报 Expecting value: line 1 column 1 (char 0)错。
问题代码如下:
import requests
import json
import jsonpath
url = "http://www.zgei.com/?name=%E6%88%91%E6%83%B3%E8%A6%81&type=qq"
r = requests.get(url=url,timeout=3)
if r.content != None:
data = json.loads(r.content.decode('utf-8-sig'))
#这里将解码成utf-8-sig 是因为会报unexpected utf-8 bom (decode using utf-8-sig) line 1 column 1 (char 0)错误
完整报错代码如下:
Traceback (most recent call last):
File "D:/pythonProject/Music_Download/1000.py", line 10, in <module>
data = json.loads(r.content.decode('utf-8-sig'))
File "D:\Python\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "D:\Python\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "D:\Python\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
json.loads()报错
查了好多种方法都还是报这个错,有说url不对应,改了也不好使,实在不知道那里的问题!!