从None提高JSONDecodeError(“期望值”,s,err.value)

时间:2018-06-22 02:29:35

标签: json import

我对网络爬虫还很陌生,我一直在尝试从H&M供应商列表中收集数据-这里的网址是:http://sustainability.hm.com/en/sustainability/downloads-resources/resources/supplier-list.html

我第一次尝试:

url = "http://sustainability.hm.com/en/sustainability/downloads-resources/resources/supplier-list.html"
r = requests.get(url)
#
json_data = r.json()

它返回:从None引发JSONDecodeError(“ Expecting value”,s,err.value)

我在线阅读了该文章,并建议对页面进行解码,因为以字节为单位,所以我尝试了建议的方法:

response = urllib.request.urlopen("http://sustainability.hm.com/en/sustainability/downloads-resources/resources/supplier-list.html").read()
data = response.read().decode('utf-8')

而且我仍然得到AttributeError:'bytes'对象没有属性'read'

我再次上网查看,它建议采用以下方法:

response = urllib.request.urlopen("http://sustainability.hm.com/en/sustainability/downloads-resources/resources/supplier-list.html").read()
jsonResponse = json.loads(response.decode('utf-8'))

但是猜猜它返回什么:从None引发JSONDecodeError(“ Expecting value”,s,err.value)

如何处理?

0 个答案:

没有答案