web抓包结果对应python request
2020-09-17 本文已影响0人
bonnie_xing
一、抓包内容
通过F12获取web网页中query-queue-rate的内容:
web抓取的包.png
二、分析
该包中包含:
General:通用信息
Response Headers:返回包头
Request Headers:请求包头
-Cookie:加密
-Host:对应的host
Form Data:请求的Data信息
三、python的request该如何填写
DATA = {'exact_key': '091198',
'sys_key': 'ipo',
'biz_key': 'ipo_stock'}
Cookie = 'uid=100001; locale=zh-cn; cipher_device_id=1600167818814682; device_id=1600167818814682; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22174917ebf429fd-09a06f098fff8e-3323767-2073600-174917ebf43114%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22%24device_id%22%3A%22174917ebf429fd-09a06f098fff8e-3323767-2073600-174917ebf43114%22%7D; web_sig=j%2FTZLVEClzkZoTylihiTTtjc2hqUJPLXLMvSZi4K3swNA2EqErrY4DX3H78lQ20q9F2EbzyETaRl994NVuZwFt37eAfDpciiVAtaSVDg6ptGmw0F1ak%2F6uFUm%2BYEK%2FLk'
host = 'https://queue.futuhk.com/queue/query-queue-rate'
r = requests.post(host, data=DATA, headers={'Host': 'queue.futuhk.com', 'Cookie': Cookie}, verify=False)
四、注意事项
- Cookie、host需要以字典的形式写入到header里面
- 不能将cookies作为字典形式,传入到request中
#错误写法
Cookie ={ 'Cookie': 'uid=100001; locale=zh-cn; cipher_device_id=1600167818814682; device_id=1600167818814682; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22174917ebf429fd-09a06f098fff8e-3323767-2073600-174917ebf43114%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22%24device_id%22%3A%22174917ebf429fd-09a06f098fff8e-3323767-2073600-174917ebf43114%22%7D; web_sig=j%2FTZLVEClzkZoTylihiTTtjc2hqUJPLXLMvSZi4K3swNA2EqErrY4DX3H78lQ20q9F2EbzyETaRl994NVuZwFt37eAfDpciiVAtaSVDg6ptGmw0F1ak%2F6uFUm%2BYEK%2FLk'}
requests.post(host, data=DATA, cookies=Cookie, headers={'Host': 'queue.futuhk.com'}, verify=False)
此时服务器那边因为字段对应不上,uid会解析错误
- 不能将cookies以字符产形式,传入到request中
#错误写法
Cookie ='uid=100001; locale=zh-cn; cipher_device_id=1600167818814682; device_id=1600167818814682; sensorsdata2015jssdkcross=%7B%22distinct_id%22%3A%22174917ebf429fd-09a06f098fff8e-3323767-2073600-174917ebf43114%22%2C%22first_id%22%3A%22%22%2C%22props%22%3A%7B%7D%2C%22%24device_id%22%3A%22174917ebf429fd-09a06f098fff8e-3323767-2073600-174917ebf43114%22%7D; web_sig=j%2FTZLVEClzkZoTylihiTTtjc2hqUJPLXLMvSZi4K3swNA2EqErrY4DX3H78lQ20q9F2EbzyETaRl994NVuZwFt37eAfDpciiVAtaSVDg6ptGmw0F1ak%2F6uFUm%2BYEK%2FLk'
requests.post(host, data=DATA, cookies=Cookie, headers={'Host': 'queue.futuhk.com'}, verify=False)
此时接口会应为传入参数类型错误,报异常