import requests
headers={
# 'Cookie': 'wdcid=7e24e0c44e0517c3',
# 'Host': 'pfsc.agri.cn',
# 'Origin': 'https://pfsc.agri.cn',
# 'Referer': 'https://pfsc.agri.cn/',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36'
}
url='https://pfsc.agri.cn/api/priceQuotationController/pageList?key=&order='
data={
"pageNum": 1,
"pageSize": 10,
"marketId": "",
"provinceCode": "",
"pid": "",
"varietyId": ""
}
# requests.packages.urllib3.disable_warnings()
res=requests.post(url=url,data=data,headers=headers).text
print(res)
现状:源码是爬取某网站json返回的数据,实际报错如标题777,
解决step1:
添加post请求参数,不验证
res=requests.post(url=url,data=data,headers=headers,verify=False).text
结果:
{
"code" : 500,
"message" : "服务故障,请稍后重试!"
}
step2:
提交的payload不应该是data应该为json
res=requests.post(url=url,json=data,headers=headers,verify=False).text
响应成功。