Bootstrap

python如何解决爬虫ip被封- - -“您操作太频繁,请稍后再访问“

描述

python 3.9.6
pycharm

问题

当我想爬取某招聘网站的信息的时候出现如下信息

{"status":false,"msg":"您操作太频繁,请稍后再访问","clientIp":"113.92.xxx.xxx","state":2402}

原因

招聘网站的反爬机制会识别访问的ip地址,没有携带hearders字段时,机制会认为是爬虫,将访问ip封了

解决方法

需要添加header,用来模拟用户登陆。
https://gitee.com/wupei_w/photo/raw/master/wupei_w/photo/20210702143029.png
右键-》copy-》copy as cURL

将复制的url复制到此链接的curl command板块
https://gitee.com/wupei_w/photo/raw/master/wupei_w/photo/20210702143317.png
将此hearders添加到代码里在这里插入图片描述
再在请求里添加headers字段

req = requests.post(url,data=data,headers=headers)

即可成功获取
在这里插入图片描述

完整代码

import requests



data = {
   
    'first'