左边
右边
页面
import requests
if __name__ == '__main__':
url = 'https://spcjsac.gsxt.gov.cn/api/goods/data'
# UA伪装
url1 = "https://spcjsac.gsxt.gov.cn/api/goods/data?food_type=&order_by=time&pageNumber=1&pageSize=10&goods_enterprise=&sampling_province=&name_first_letter=&food_name=&bar_code=&check_flag=q"
headers = {
"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36',
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
"Accept": "application/json, text/javascript, */*; q=0.01",
"Connection": "keep-alive"
}
data = {
'food_type': '',
'order_by': 'time',
'pageNumber': '1',
'pageSize': '10',
'goods_enterprise': '广东',
'sampling_province': '',
'name_first_letter': '',
'food_name': '',
'bar_code': '',
'check_flag': 'uq'
}
# response = requests.get(url=url1, data=data, headers=headers,verify=False)
response = requests.post(url=url, data=data, headers=headers).json()
print(response)
这个错误跟python 版本,openssl 版本有关。。以上代码在python 3.6 版本运行成功,你换个版本吧
有人能帮帮我吗
为什么不会爬,你都分析对了啊。就是那个uq 和q 控制左右的。uq 是不安全。q是符合质量的列表
https://spcjsac.gsxt.gov.cn/api/goods/data?food_type=&order_by=time&pageNumber=1&pageSize=10&goods_enterprise=&sampling_province=&name_first_letter=&food_name=&bar_code=&check_flag=q
我的代码:
import requests
import json
if name == 'main':
url = 'https://spcjsac.gsxt.gov.cn/api/goods/data'
data = {
'food_type':'',
'order_by': 'time',
'pageNumber': '1',
'pageSize': '10',
'goods_enterprise': '广东',
'sampling_province': '',
'name_first_letter': '',
'food_name': '',
'bar_code': '',
'check_flag': 'q'
}
#UA伪装
headers = {
'user-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.54 Safari/537.36'
}
response = requests.post(url=url,data=data,headers=headers)
food_obj = response.json()
print(food_obj)
fp = open('./food.json','w',encoding='utf-8')
json.dump(food_obj,fp=fp,ensure_ascii=False)
print('爬取成功!!!')
报错:
这个可以实施其他的方法