一点也没有出乎意料,滑动验证码用python来解决也并不难!
一、介绍
一些网站会在正常的账号密码认证之外加一些验证码,以此来明确地区分人 / 机行为,从一定程度上达到反爬的效果,对于简单的校验码 Tesserocr 就可以搞定,如下
但一些网站加入了滑动验证码,最典型的要属于极验滑动认证了
对于这类验证,如果我们直接模拟表单请求,繁琐的认证参数与认证流程会让你蛋碎一地,我们可以用 selenium 驱动浏览器来解决这个问题,大致分为以下几个步骤
1、输入账号、密码,然后点击登陆
2、点击按钮,弹出没有缺口的图
3、针对没有缺口的图片进行截图
4、点击滑动按钮,弹出有缺口的图
5、针对有缺口的图片进行截图
6、对比两张图片,找出缺口,即滑动的位移
7、按照人的行为行为习惯,把总位移切成一段段小的位移
8、按照位移移动
9、完成登录
二、实现
安装:selenium+chrome/phantomjs
安装:Pillow
Pillow: 基于 PIL,处理 python 3.x 的图形图像库. 因为 PIL 只能处理到 python 2.x,而这个模块能处理 Python3.x,目前用它做图形的很多.
<pre style="-webkit-tap-highlight-color: transparent; box-sizing: border-box; font-family: Consolas, Menlo, Courier, monospace; font-size: 16px; white-space: pre-wrap; position: relative; line-height: 1.5; color: rgb(153, 153, 153); margin: 1em 0px; padding: 12px 10px; background: rgb(244, 245, 246); border: 1px solid rgb(232, 232, 232); font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">C:UsersAdministrator>pip3 install pillowC:UsersAdministrator>python3
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.>> from PIL import Image>>
</pre>
三、案例
1. 破解博客园后台登陆
2. 修订版博客园后台登陆
四、方法
1. 用类封装的版本 svcr
2. 使用类