代码
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