⭐️⭐️⭐️⭐️⭐️欢迎来到我的博客⭐️⭐️⭐️⭐️⭐️
🐴作者:秋无之地🐴简介:CSDN爬虫、后端、大数据领域创作者。目前从事python爬虫、后端和大数据等相关工作,主要擅长领域有:爬虫、后端、大数据开发、数据分析等。
🐴欢迎小伙伴们点赞👍🏻、收藏⭐️、留言💬、关注🤝,关注必回关
一、确定目标
1、先打开目标网站,找到目标所在的页面
2、找到所需的参数
根据上图可知,整个登录流程需要的参数有:账号、密码、验证码,而且验证码还是图形算式验证码。
3、了解登录流程,找到对应的接口
打开F12 ,刷新页面可以看到验证码的生成接口,返回的是验证码的图片信息和一个uuid的参数
4、测试登录,找到登录的接口
所以,整个登录的流程一共就2个接口,分别如下:
生成验证码接口:
https://ad.clroi.com/prod-api/code
登录接口:
https://ad.clroi.com/prod-api/auth/login
二、分析接口
1、生成验证码接口
接口的请求方式为:get
请求头参数也是常见的几个,没有加密的参数
Host、Referer、User-Agent:建议必带
返回的参数:
1、img:验证码图片,不过需要加前缀"data:image/gif;base64,"才能组成完整的图片链接
2、uuid:唯一建,用于登录接口的请求参数
#返回参数:
{"msg": "操作成功","img": "/9j/4AAQSkZJRgABAgAAAQABAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAA8AKADASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISUpTVFVWV1hZWmNkZWZnaGlqc3R1dnd4eXqDhIWGh4iJipKTlJWWl5iZm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X6h/zxtv8Avlv/AIqj20Q9tE7YCngVw/8AwmGof88bX/vlv/iqX/hMtR/542v/AHy3/wAVR7aIe2id0BS7QetcL/wmeo/88bX/AL4b/wCKpf8AhNdS/wCeFp/3w3/xVHtoh7aJ3ioBUgrgP+E21L/nhaf98N/8VS/8Jxqf/PC0/wC+G/8AiqPbRD20T0EVV1f/AJAeof8AXtJ/6Ca4r/hOdT/54Wn/AHw3/wAVUdz4z1G6tZrd4bUJKjIxVWyARjj5qmVaNmKVWNmf/9k=","code": 200,"captchaOnOff": true,"uuid": "50d10c7521ad42f8b313aa8bb19c2b04"
}
这是,验证码接口就解决了,简单吧!
2、登录接口
接口的请求方式为:post
请求头参数也是常见的几个,没有加密的参数
Host、Referer、User-Agent:建议必带
请求体参数:
1、code:验证码的结果
2、password:密码
3、username:账号
4、uuid:验证码接口返回的参数
这时候有人会问了,上面验证码接口的一个图片链接,现在传递的参数是一个字符串,怎么办?
方法有好多种:
- 找打码平台,例如百度AI打码
- 使用ocr识别(需要训练)
- 将图片截图发到手机里,人工识别后回传信息给程序继续下一步登录
返回参数:
1、access_token:登录的token,需要加前缀"Bearer "后续请求数据接口才能用
2、code:200表示成功,500表示失败
三、代码编写
1、获取验证码信息
def get_code(self):'''获取登录验证码:return:'''try:url = "https://ad.clroi.com/prod-api/code"header = {"Referer": "https://ad.clroi.com/login?redirect=%2Findex","Host":"ad.clroi.com","User-Agent":self.ua,"Accept":"application/json, text/plain, */*",}resp = requests.get(url,headers=header).json()if resp['code']==200:code_img = "data:image/gif;base64," + resp['img']code_uuid = resp['uuid']#破解验证码code_num = self.down_code_img(code_img=code_img)print("验证码:",code_num," ,uuid:",code_uuid)auth = self.get_token(login_code=code_num, uuid=code_uuid)else:auth = ""return authexcept Exception as e:print(e)return ""
2、登录获取token
def get_token(self,login_code=None,uuid=None):'''获取token:return:'''try:url = "https://ad.clroi.com/prod-api/auth/login"header = {"User-Agent":self.ua,"Content-Type":"application/json;charset=UTF-8",}data = {"username": "XXXX", "password": "XXXX", "code": login_code, "uuid": uuid}resp = requests.post(url,headers=header,json=data).json()print(resp)if resp['code']==200:auth = "Bearer " + resp['data']['access_token']return authexcept Exception as e:print(e)
四、总结
模拟登录的步骤不难,主要是以下三点:
- 确定目标
- 分析接口
- 代码编写
版权声明
本文章版权归作者所有,未经作者允许禁止任何转载、采集,作者保留一切追究的权利。