bitmon 2022-05-09 15:24 采纳率: 0%
浏览 349

运行课程爬虫代码后报错,代码和报错如下,求解!

代码
import requests
import json
if name == "main":
# url = 'http://scxk.nmpa.gov.cn:81/xk/'
# UA伪装
headers = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.60 Safari/537.36'
} # 同时按住 ctrl+/ 注释多行
# 批量获取公司id
# 指定url
url = 'http://scxk.nmpa.gov.cn:81/xk/itownet/portalAction.do?hKHnQfLv=50ewshnlRiyay7QbK_ecpyf1t38FxmrH_qWVk913wR9TbWLtS992Svim2a.dOoboH2CUOOyynMEfU9UWCiGVt.2CIpPCECynCwDJtjSwJzb34wPVUBRr6JCPHoBAiQeT9TepWPvCiqCyyYX0l4hiJlPZqIqnJkK7NUm8oKkPCQSCnZ3OajG0U2h1.iRwMeSrfTWrWMq.KHZ0WoroCfj64yPnN5QIBJrkpcN2HEz6IMibUZegnvusfH2Q2sAvky.eSYd4x6FnBaVB4hOxxhNX6cvSHB8pcSZClTcAa_3YDZR9&8X7Yi61c=461tIc.U3jJagyJcGLJOZKZSCPbHAzRw7EgsMZvZiN3Mic35oV_jr_cNNLXDlciLVPL12uztqBrWCZW_eKcsVICX5wKErnPyOA0R6SwsmlX29FzkYhomKhFjGWDUEQIzj'
data = {
'on': 'true',
'page': '1',
'pageSize': '15',
'productName': '',
'conditionType': '1',
'applyname': '',
'applysn': '',
}
id_list = [] # 存储企业id
response = requests.post(url=url, data=data, headers=headers)
json_ids = response.json()
for dic in json_ids["list"]:
id_list.append(dic['ID'])
print(id_list)

报错
Traceback (most recent call last):
File "D:\python text\xiaxie\venv\lib\site-packages\requests\models.py", line 910, in json
return complexjson.loads(self.text, **kwargs)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\json_init_.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\admin\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 4 column 1 (char 6)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "D:\python text\xiaxie\request爬取案例\药监总局化妆品实例.py", line 24, in
json_ids = response.json()
File "D:\python text\xiaxie\venv\lib\site-packages\requests\models.py", line 917, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: [Errno Expecting value]

: 6

Process finished with exit code 1

  • 写回答

3条回答 默认 最新

  • 溪风沐雪 2022-05-09 15:34
    关注

    你这个代码访问结果response没有内容,是400错误,网址或者传参有问题
    <Response [400]>

    评论

报告相同问题?

问题事件

  • 创建了问题 5月9日