当前位置:   article > 正文

java爬虫破解滑块验证码_计算缺口滑块图和完整滑块图者差距

计算缺口滑块图和完整滑块图者差距

使用技术:java+Selenium

废话:

        有爬虫,自然就有反爬虫,就像病毒和杀毒软件一样,有攻就有防,两者彼此推进发展。而目前最流行的反爬技术验证码,为了防止爬虫自动注册,批量生成垃圾账号,几乎所有网站的注册页面都会用到验证码技术。其实验证码的英文为 CAPTCHA(Completely Automated Public Turing test to tell Computers and Humans Apart),翻译成中文就是全自动区分计算机和人类的公开图灵测试,它是一种可以区分用户是计算机还是人的测试,只要能通过 CAPTCHA 测试,该用户就可以被认为是人类。由此也可知道破解滑块验证码的关键即是让计算机更好的模拟人的行为


破解无缺口滑块

无缺口滑块如下图:

 

 滑块代码:

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
  6. <meta http-equiv="Pragma" content="no-cache">
  7. <meta http-equiv="Expires" content="0">
  8. <meta http-equiv="X-UA-Compatible" content="IE-Edge,chrome=1">
  9. <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no">
  10. <meta content="yes" name="apple-mobile-web-app-capable">
  11. <meta content="black" name="apple-mobile-web-app-status-bar-style">
  12. <meta content="telephone=no" name="format-detection">
  13. <meta content="email=no" name="format-detection">
  14. <title>拖动滑块验证</title>
  15. <meta name="description" content="">
  16. <meta name="keywords" content="">
  17. <link rel="stylesheet" type="text/css" href="">
  18. <style>
  19. * {
  20. margin: 0;
  21. padding: 0;
  22. }
  23. body {
  24. font: 12px/1.125 Microsoft YaHei;
  25. background: #fff;
  26. }
  27. ul, li {
  28. list-style: none;
  29. }
  30. a {
  31. text-decoration: none;
  32. }
  33. .ani {
  34. transition: all .3s;
  35. }
  36. .wrap {
  37. width: 300px;
  38. height: 350px;
  39. text-align: center;
  40. margin: 150px auto;
  41. }
  42. .inner {
  43. padding: 15px;
  44. }
  45. .clearfix {
  46. overflow: hidden;
  47. _zoom: 1;
  48. }
  49. .none {
  50. display: none;
  51. }
  52. #slider {
  53. position: relative;
  54. background-color: #e8e8e8;
  55. width: 300px;
  56. height: 34px;
  57. line-height: 34px;
  58. text-align: center;
  59. }
  60. #slider .handler {
  61. position: absolute;
  62. top: 0px;
  63. left: 0px;
  64. width: 40px;
  65. height: 32px;
  66. border: 1px solid #ccc;
  67. cursor: move;
  68. }
  69. .handler_bg {
  70. background: #fff url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAA3hpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADw/eHBhY2tldCBiZWdpbj0i77u/IiBpZD0iVzVNME1wQ2VoaUh6cmVTek5UY3prYzlkIj8+IDx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IkFkb2JlIFhNUCBDb3JlIDUuNS1jMDIxIDc5LjE1NTc3MiwgMjAxNC8wMS8xMy0xOTo0NDowMCAgICAgICAgIj4gPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4gPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIgeG1sbnM6eG1wTU09Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC9tbS8iIHhtbG5zOnN0UmVmPSJodHRwOi8vbnMuYWRvYmUuY29tL3hhcC8xLjAvc1R5cGUvUmVzb3VyY2VSZWYjIiB4bWxuczp4bXA9Imh0dHA6Ly9ucy5hZG9iZS5jb20veGFwLzEuMC8iIHhtcE1NOk9yaWdpbmFsRG9jdW1lbnRJRD0ieG1wLmRpZDo0ZDhlNWY5My05NmI0LTRlNWQtOGFjYi03ZTY4OGYyMTU2ZTYiIHhtcE1NOkRvY3VtZW50SUQ9In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gZW5kPSJyIj8+k+sHwwAAASZJREFUeNpi/P//PwMyKD8uZw+kUoDYEYgloMIvgHg/EM/ptHx0EFk9I8wAoEZ+IDUPiIMY8IN1QJwENOgj3ACo5gNAbMBAHLgAxA4gQ5igAnNJ0MwAVTsX7IKyY7L2UNuJAf+AmAmJ78AEDTBiwGYg5gbifCSxFCZoaBMCy4A4GOjnH0D6DpK4IxNSVIHAfSDOAeLraJrjgJp/AwPbHMhejiQnwYRmUzNQ4VQgDQqXK0ia/0I17wJiPmQNTNBEAgMlQIWiQA2vgWw7QppBekGxsAjIiEUSBNnsBDWEAY9mEFgMMgBk00E0iZtA7AHEctDQ58MRuA6wlLgGFMoMpIG1QFeGwAIxGZo8GUhIysmwQGSAZgwHaEZhICIzOaBkJkqyM0CAAQDGx279Jf50AAAAAABJRU5ErkJggg==") no-repeat center;
  74. }
  75. #slider .drag_bg {
  76. background-color: #7ac23c;
  77. height: 34px;
  78. width: 0px;
  79. }
  80. #slider .drag_text {
  81. position: absolute;
  82. top: 0px;
  83. width: 300px;
  84. -moz-user-select: none;
  85. -webkit-user-select: none;
  86. user-select: none;
  87. -o-user-select: none;
  88. -ms-user-select: none;
  89. }
  90. .unselect {
  91. -moz-user-select: none;
  92. -webkit-user-select: none;
  93. -ms-user-select: none;
  94. }
  95. .slide_ok {
  96. color: #fff;
  97. }
  98. </style>
  99. </head>
  100. <body>
  101. <div class="wrap">
  102. <div id="slider">
  103. <div class="drag_bg"></div>
  104. <div class="drag_text" onselectstart="return false;" unselectable="on">拖动滑块验证</div>
  105. <div class="handler handler_bg"></div>
  106. </div>
  107. </div>
  108. <script>
  109. (function (window, document, undefined) {
  110. var dog = {//声明一个命名空间,或者称为对象
  111. $: function (id) {
  112. return document.querySelector(id);
  113. },
  114. on: function (el, type, handler) {
  115. el.addEventListener(type, handler, false);
  116. },
  117. off: function (el, type, handler) {
  118. el.removeEventListener(type, handler, false);
  119. }
  120. };
  121. //封装一个滑块类
  122. function Slider() {
  123. var args = arguments[0];
  124. for (var i in args) {
  125. this[i] = args[i]; //一种快捷的初始化配置
  126. }
  127. //直接进行函数初始化,表示生成实例对象就会执行初始化
  128. this.init();
  129. }
  130. Slider.prototype = {
  131. constructor: Slider,
  132. init: function () {
  133. this.getDom();
  134. this.dragBar(this.handler);
  135. },
  136. getDom: function () {
  137. this.slider = dog.$('#' + this.id);
  138. this.handler = dog.$('.handler');
  139. this.bg = dog.$('.drag_bg');
  140. },
  141. dragBar: function (handler) {
  142. var that = this,
  143. startX = 0,
  144. lastX = 0,
  145. doc = document,
  146. width = this.slider.offsetWidth,
  147. max = width - handler.offsetWidth,
  148. drag = {
  149. down: function (e) {
  150. var e = e || window.event;
  151. that.slider.classList.add('unselect');
  152. startX = e.clientX - handler.offsetLeft;
  153. console.log('startX: ' + startX + ' px');
  154. dog.on(doc, 'mousemove', drag.move);
  155. dog.on(doc, 'mouseup', drag.up);
  156. return false;
  157. },
  158. move: function (e) {
  159. var e = e || window.event;
  160. lastX = e.clientX - startX;
  161. lastX = Math.max(0, Math.min(max, lastX)); //这一步表示距离大于0小于max,巧妙写法
  162. console.log('lastX: ' + lastX + ' px');
  163. if (lastX >= max) {
  164. handler.classList.add('handler_ok_bg');
  165. that.slider.classList.add('slide_ok');
  166. dog.off(handler, 'mousedown', drag.down);
  167. drag.up();
  168. }
  169. that.bg.style.width = lastX + 'px';
  170. handler.style.left = lastX + 'px';
  171. },
  172. up: function (e) {
  173. var e = e || window.event;
  174. that.slider.classList.remove('unselect');
  175. if (lastX < width) {
  176. that.bg.classList.add('ani');
  177. handler.classList.add('ani');
  178. that.bg.style.width = 0;
  179. handler.style.left = 0;
  180. setTimeout(function () {
  181. that.bg.classList.remove('ani');
  182. handler.classList.remove('ani');
  183. }, 300);
  184. }
  185. dog.off(doc, 'mousemove', drag.move);
  186. dog.off(doc, 'mouseup', drag.up);
  187. }
  188. };
  189. dog.on(handler, 'mousedown', drag.down);
  190. }
  191. };
  192. window.S = window.Slider = Slider;
  193. })(window, document);
  194. var defaults = {
  195. id: 'slider'
  196. };
  197. new S(defaults);
  198. </script>
  199. </body>
  200. </html>

分析

1.查看滑块按钮大小

 2.查看滑块大小

 从上面2张图得出拖动距离为(300-40)px

爬虫代码

  1. public static void main(String[] args) throws Exception {
  2. System.setProperty("webdriver.chrome.driver","D:\\demo\\selenumDemo\\src\\main\\resources\\chromedriver.exe");
  3. WebDriver driver = new ChromeDriver();
  4. try {
  5. driver.get("file:///C:/Users/Administrator/Desktop/index.html");
  6. WebElement Slider = driver.findElement(By.cssSelector(".handler.handler_bg"));// 拿到滑块按钮
  7. Thread.sleep(2000L);
  8. // 实例化鼠标操作对象Actions
  9. Actions action = new Actions(driver);
  10. action.dragAndDropBy(Slider,260,0).perform();// 移动一定位置
  11. Thread.sleep(5000L);
  12. } catch (InterruptedException e) {
  13. e.printStackTrace();
  14. }finally{
  15. // driver.close();// 关闭页面
  16. driver.quit();// 释放资源
  17. }
  18. }

注意:有的网站拖完后可能验证成功,有的可能失败,失败的童鞋也不要慌张,因为被网站检测出你用的是爬虫操作的,我有妙计!接着往下看!

先分分析一波!1.使用驱动打开浏览器

  1. public static void openChrome(){
  2. System.setProperty("webdriver.chrome.driver","D:\\demo\\selenumDemo\\src\\main\\resources\\chromedriver.exe");
  3. // 1.打开Chrome浏览器
  4. chromeDriver = new ChromeDriver();
  5. chromeDriver.get("url...");
  6. }

2.然后 f12打开console控制台输入:window.navigator.webdriver

 发现值是true,但是我们正常手动打开浏览器他却是false或者undefined,如下图

 

所以得出结论网站通过代码获取这个参数,返回值undefined或者false是正常浏览器,返回true说明用的是Selenium模拟浏览器,所以解决还是要从驱动浏览器解决,在启动Chromedriver之前,来隐藏它

  1. public static void openChrome(){
  2. // 隐藏 window.navigator.webdriver
  3. ChromeOptions option = new ChromeOptions();
  4. option.setExperimentalOption("useAutomationExtension", false);
  5. option.setExperimentalOption("excludeSwitches", Lists.newArrayList("enable-automation"));
  6. option.addArguments("--disable-blink-features=AutomationControlled");//主要是这句是关键
  7. System.setProperty("webdriver.chrome.driver","D:\\demo\\selenumDemo\\src\\main\\resources\\chromedriver.exe");
  8. // 1.打开Chrome浏览器
  9. chromeDriver = new ChromeDriver(option);
  10. chromeDriver.get("URL...");
  11. }

然后再次启动查看就变成了false


破解缺口滑块

缺口滑块如下图:

 分析

我拿某网站的滑块源代码来分析,如下图可以看出缺口滑块图是由canvas绘制的。

 1.我们要做的是找到缺口的X坐标,所以需要拿到完整图片和缺口图片进行计算,但是我们只能看见一张缺口图片,但是我们只要在canvas的css加一行代码style="display:none"

 然后再看就出现了没有拼图阻挡的缺口图

 

 2.然后在下面的canvas 修改style="display:block"就可以看到完整图片如下下图

然后再看发现看到了完整的图

 

 3.然后使用selenium的截图方法,把原图和缺口图保存下来,然后再拿着像素对比可以算出按钮位置与缺口X坐标


爬虫代码

  1. public class ElementLocate {
  2. private static ChromeDriver chromeDriver;
  3. public static void main(String[] args) throws InterruptedException, IOException {
  4. openChrome();// 打开浏览器等操作
  5. try {
  6. chromeDriver.manage().window().maximize();// 浏览器最大化
  7. // 等待滑块加载完毕
  8. new WebDriverWait(chromeDriver, 5)
  9. .until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@aria-label='点击按钮进行验证']")));
  10. // 点开滑块
  11. chromeDriver.findElementByXPath("//div[@aria-label='点击按钮进行验证']").click();// 点开验证框
  12. operateSlider();// 操作滑块
  13. } finally {
  14. chromeDriver.quit();//测试完要停止 不然卡成球
  15. }
  16. }
  17. private static void openChrome() {
  18. // 配置浏览器
  19. ChromeOptions option = new ChromeOptions();
  20. option.setExperimentalOption("useAutomationExtension", false);
  21. option.setExperimentalOption("excludeSwitches", Lists.newArrayList("enable-automation"));
  22. option.addArguments("--disable-blink-features=AutomationControlled");//主要是这句是关键,防止网站js检测出爬虫
  23. // set浏览器驱动
  24. System.setProperty("webdriver.chrome.driver", "D:\\demo\\selenumDemo\\src\\main\\resources\\chromedriver.exe");
  25. // 打开Chrome浏览器
  26. chromeDriver = new ChromeDriver(option);
  27. // 访问百度
  28. chromeDriver.get("https://account.zbj.com/login?lgtype=1&waytype=603&fromurl=https%3A%2F%2Fxiamen.zbj.com%2F");
  29. }
  30. // 操作元素属性
  31. private static void setAttribute(WebDriver driver, WebElement element, String attributeName, String value) {
  32. JavascriptExecutor js = (JavascriptExecutor) driver;
  33. js.executeScript("arguments[0].setAttribute('" + attributeName + "', '" + value + "')", element);
  34. }
  35. //删除元素属性
  36. private void removeAttribute(WebDriver driver, WebElement element, String attributeName) {
  37. JavascriptExecutor js = (JavascriptExecutor) driver;
  38. js.executeScript("argument[0].removeAttribute(argumentp[1]),argument[2]", element, attributeName);
  39. }
  40. // 截图
  41. private static File captureElement(File screenshot, WebElement element) {
  42. try {
  43. BufferedImage img = ImageIO.read(screenshot);
  44. int width = element.getSize().getWidth();
  45. int height = element.getSize().getHeight();
  46. //获取指定元素的坐标
  47. Point point = element.getLocation();
  48. //从元素左上角坐标开始,按照元素的高宽对img进行裁剪为符合需要的图片
  49. BufferedImage dest = img.getSubimage(point.getX(), point.getY(), width, height);
  50. ImageIO.write(dest, "png", screenshot);
  51. } catch (IOException e) {
  52. e.printStackTrace();
  53. }
  54. return screenshot;
  55. }
  56. // 操作滑块
  57. private static void operateSlider() throws InterruptedException, IOException {
  58. Thread.sleep(1000);// 重复获取元素必须sleep,否则会报错!
  59. //修改元素属性,显示缺口滑块图,这里需要等图片加载出来,如果网络慢没加载出来会报错
  60. WebElement que1 = chromeDriver.findElementByXPath("//div[@class='geetest_slicebg geetest_absolute']/canvas[@class='geetest_canvas_slice geetest_absolute']");
  61. setAttribute(chromeDriver, que1, "style", "display:none");
  62. // 截图滑块缺口图片
  63. WebElement quekou = chromeDriver.findElementByXPath("//canvas[@class='geetest_canvas_bg geetest_absolute']");
  64. File src = chromeDriver.getScreenshotAs(OutputType.FILE);
  65. FileUtils.copyFile(src, new File("D:\\result.png"));
  66. FileUtils.copyFile(captureElement(src, quekou), new File("D:\\test.png"));
  67. // 修改元素属性,显示完整滑块图
  68. WebElement que2 = chromeDriver.findElementByXPath("//canvas[@class='geetest_canvas_fullbg geetest_fade geetest_absolute']");
  69. setAttribute(chromeDriver, que2, "style", "display:block");
  70. // 截图滑块完整图
  71. WebElement wanzheng = chromeDriver.findElementByXPath("//canvas[@class='geetest_canvas_bg geetest_absolute']");
  72. File src2 = chromeDriver.getScreenshotAs(OutputType.FILE);
  73. FileUtils.copyFile(src2, new File("D:\\result1.png"));
  74. FileUtils.copyFile(captureElement(src2, wanzheng), new File("D:\\test1.png"));
  75. // 还原滑块
  76. WebElement huanyuan1 = chromeDriver.findElementByXPath("//canvas[@class='geetest_canvas_fullbg geetest_fade geetest_absolute']");
  77. setAttribute(chromeDriver, huanyuan1, "style", "display:none");
  78. WebElement huanyuan2 = chromeDriver.findElementByXPath("//canvas[@class='geetest_canvas_slice geetest_absolute']");
  79. setAttribute(chromeDriver, huanyuan2, "style", "display:block");
  80. // 计算缺口滑块图和完整滑块图者差距,5为滑块按钮和滑块图左边的差5px
  81. int moveDistance = getMoveDistance() - 5;
  82. // 拿到滑块按钮
  83. WebElement btn = chromeDriver.findElementByXPath("//div[@class='geetest_slider_button']");
  84. // 拿到鼠标操作,实例化Actions
  85. Actions actions = new Actions(chromeDriver);
  86. // 把滑块->缺口距离分成多份
  87. int[] nums = split(moveDistance);
  88. // 移动滑块按钮
  89. Random random = new Random();
  90. String time = "35";
  91. for (int i = 0; i < nums.length; i++) {
  92. actions.clickAndHold(btn).moveByOffset(nums[i], 0)
  93. .build().perform();
  94. int times = Integer.parseInt(time + random.nextInt(10));
  95. Thread.sleep(times);
  96. }
  97. // 模拟人操作
  98. actions.clickAndHold(btn).moveByOffset(-1, 0).release()
  99. .build().perform();
  100. Thread.sleep(3000);// 滑块完成等待2秒判断是否验证成功
  101. // 是否滑块成功
  102. String attribute = chromeDriver.findElementByXPath("//div[@class='geetest_radar_tip']").getAttribute("aria-label");
  103. System.out.println("attribute = " + attribute);
  104. if (attribute.equals("网络不给力") ) {
  105. chromeDriver.findElementByXPath("//div[@class='geetest_radar_tip']").click();
  106. // 再次滑块
  107. operateSlider();
  108. }
  109. }
  110. // 整数拆分
  111. private static int[] split(int num) {
  112. int[] nums = new int[5];
  113. Random rand = new Random();
  114. for (int i = 0; i < nums.length - 1; i++) {
  115. nums[i] = rand.nextInt(num);
  116. num -= nums[i];
  117. }
  118. nums[nums.length - 1] = num;
  119. return nums;
  120. }
  121. }

注意:滑块按钮滑到指定区域,可能会出现滑块被吃掉的情况!这是因为被判定为机器操作,所以要尽量模拟出人的速度滑一定的距离停止n毫秒,经过我不断的调试,这样可以减少被误判的几率。成功率在80%左右。

 这是小编在开发学习使用和总结的小Demo,  这中间或许也存在着不足,希望可以得到大家的理解和建议。如有侵权联系小编!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/287124?site
推荐阅读
相关标签
  

闽ICP备14008679号