1、引用 selenium 包

<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>4.29.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>4.29.0</version>
</dependency>
<dependency>
<groupId>org.openqa.selenium</groupId>
<artifactId>selenium-support</artifactId>
<version>4.29.0</version>
</dependency>

2、下载 chromedriver

下载地址:https://chromedriver.storage.googleapis.com/index.html

这里引用包支持版本为 114,我下载使用的是 114.0.5734.0,分为 windows版本以及 linux 版本。

114这个版本的 chromedriver 软件将放在源码中供大家学习使用。

3、对应的浏览器下载

由于chromedriver 最新版本为 114所以,最新的 chrome浏览器无法使用只能下载114这个版本chrome浏览器。

linux 下载地址:

https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Linux%2F114059%2Fchrome-linux.zip?generation=1&alt=media

windows下载地址:

https://www.googleapis.com/download/storage/v1/b/chromium-browser-snapshots/o/Win_x64%2F1140629%2Fchrome-win.zip?generation=1683480562257014&alt=media

4、具体现实代码

public static void main(String[] args) throws IOException {

    // 设置 ChromeDriver 路径
System.setProperty("webdriver.chrome.driver", "D:\\Project\\web-crawler\\chromedriver\\chromedriver.exe"); // 配置 Chrome 浏览器
ChromeOptions options = new ChromeOptions();
// 如果不想显示浏览器界面
// options.addArguments("--headless");
// 设置启动时最大化浏览器窗口
options.addArguments("--start-maximized");
// 指定浏览器位置
options.setBinary("D:\\Project\\web-crawler\\chrome-windows\\chrome.exe");
WebDriver driver = new ChromeDriver(options);
driver.get("http://182.131.3.xxx:8000/noticerpt/user/popup_login"); // 显式等待,确保登录页面加载完成
WebDriverWait loginWait = new WebDriverWait(driver, Duration.ofSeconds(30));
// 获取背景图和拼图块
// 拼图背景图
WebElement button = loginWait.until(ExpectedConditions.presenceOfElementLocated(By.className("button4")));
button.click();
WebElement automv = loginWait.until(ExpectedConditions.presenceOfElementLocated(By.id("automv_1")));
WebElement aBtn = automv.findElement(By.tagName("a"));
aBtn.click(); // 拼图块
WebElement nav = driver.findElement(By.id("nav"));
List<WebElement> elementList = nav.findElements(By.tagName("li"));
WebElement navLi = elementList.get(1);
WebElement navLiA = navLi.findElement(By.tagName("a"));
navLiA.click(); WebElement smsLoginFormsc = driver.findElement(By.id("smsLoginFormsc"));
WebElement embedCaptchaSms = smsLoginFormsc.findElement(By.id("embed-captcha-sms"));
WebElement gtSlider = embedCaptchaSms.findElement(By.className("gt_slider"));
WebElement gtSliderKnob = gtSlider.findElement(By.className("gt_slider_knob"));
new Actions(driver).moveToElement(gtSliderKnob).perform(); // WebElement gtWidget = smsLoginFormsc.findElement(By.className("gt_widget"));
// WebElement gtWidget = smsLoginFormsc.findElement(By.className("gt_widget"));
// WebElement gtWidget = smsLoginFormsc.findElement(By.className("gt_widget")); // 获取拼图块的位置
// Point sliderPosition = slider.getLocation();
// System.out.println("拼图块的初始位置: " + sliderPosition); // // 计算缺失的拼图块位置(假设通过图像处理得出:x = 200, y = 0)
// int targetX = 200;
// int targetY = 0;
// String imageUrl = backgroundElement.getAttribute("src");
// BufferedImage background = ImageIO.read(new URL(imageUrl));
// imageUrl = puzzlePieceElement.getAttribute("src");
// BufferedImage puzzlePiece = ImageIO.read(new URL(imageUrl));
//
// // 比较两张图片的差异
// int diffX = 0;
// int diffY = 0;
//
// for (int y = 0; y < background.getHeight(); y++) {
// for (int x = 0; x < background.getWidth(); x++) {
// int bgPixel = background.getRGB(x, y);
// int puzzlePixel = puzzlePiece.getRGB(x, y);
//
// if (bgPixel != puzzlePixel) {
// diffX = x;
// diffY = y;
// break;
// }
// }
// } // 获取拼图块的当前位置
// Point start = slider.getLocation(); // // 模拟滑动拼图块
// Actions actions = new Actions(driver);
// actions.clickAndHold(slider)
// .moveByOffset(targetX - start.getX(), targetY - start.getY())
// .release()
// .perform(); // 等待拼图验证完成
// WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
// wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("success-message")));
//
// System.out.println("拼图解锁成功!"); // 关闭浏览器
// driver.quit(); }

  

以上代码主要就是实现关闭弹窗、显示滑动拼图验证码。其中代码

http://182.131.3.xxx:8000/noticerpt/user/popup_login  xxx 为了安逸将最后一段修改为了XXX根据逻辑可以修改为自己的业务需求

5、总结

只是个人作为研究的手抄还是有很多不足,而且具体逻辑也没有写(但是会持续的更新)

6、代码

爬虫代码:维基框架/wiki-web-crawler

如果觉得还不错误,请支持一下作者开源框架 维基框架  维基代理

使用 chromedriver 实现网络爬虫【手抄】的更多相关文章

  1. [原创]手把手教你写网络爬虫(5):PhantomJS实战

    手把手教你写网络爬虫(5) 作者:拓海 摘要:从零开始写爬虫,初学者的速成指南! 封面: 大家好!从今天开始,我要与大家一起打造一个属于我们自己的分布式爬虫平台,同时也会对涉及到的技术进行详细介绍.大 ...

  2. Python3 网络爬虫(请求库的安装)

    Python3 网络爬虫(请求库的安装) 爬虫可以简单分为几步:抓取页面,分析页面和存储数据 在页面爬取的过程中我们需要模拟浏览器向服务器发送请求,所以需要用到一些python库来实现HTTP的请求操 ...

  3. Python3之网络爬虫<0>初级

    由于Python3合并URLib与URLlib2统一为URLlib,Python3将urlopen方法放在了urllib.request对象下. 官方文档:https://docs.python.or ...

  4. python网络爬虫之自动化测试工具selenium[二]

    目录 前言 一.获取今日头条的评论信息(request请求获取json) 1.分析数据 2.获取数据 二.获取今日头条的评论信息(selenium请求获取) 1.分析数据 2.获取数据 房源案例(仅供 ...

  5. Python3网络爬虫开发实战PDF高清完整版免费下载|百度云盘

    百度云盘:Python3网络爬虫开发实战高清完整版免费下载 提取码:d03u 内容简介 本书介绍了如何利用Python 3开发网络爬虫,书中首先介绍了环境配置和基础知识,然后讨论了urllib.req ...

  6. Python初学者之网络爬虫(二)

    声明:本文内容和涉及到的代码仅限于个人学习,任何人不得作为商业用途.转载请附上此文章地址 本篇文章Python初学者之网络爬虫的继续,最新代码已提交到https://github.com/octans ...

  7. 网络爬虫:使用Scrapy框架编写一个抓取书籍信息的爬虫服务

      上周学习了BeautifulSoup的基础知识并用它完成了一个网络爬虫( 使用Beautiful Soup编写一个爬虫 系列随笔汇总 ), BeautifulSoup是一个非常流行的Python网 ...

  8. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(3): 抓取amazon.com价格

    通过上一篇随笔的处理,我们已经拿到了书的书名和ISBN码.(网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息 ...

  9. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(2): 抓取allitebooks.com书籍信息及ISBN码

    这一篇首先从allitebooks.com里抓取书籍列表的书籍信息和每本书对应的ISBN码. 一.分析需求和网站结构 allitebooks.com这个网站的结构很简单,分页+书籍列表+书籍详情页. ...

  10. 网络爬虫: 从allitebooks.com抓取书籍信息并从amazon.com抓取价格(1): 基础知识Beautiful Soup

    开始学习网络数据挖掘方面的知识,首先从Beautiful Soup入手(Beautiful Soup是一个Python库,功能是从HTML和XML中解析数据),打算以三篇博文纪录学习Beautiful ...

随机推荐

  1. RabbitMQ(五)——发布订阅模式

    RabbitMQ系列 RabbitMQ(一)--简介 RabbitMQ(二)--模式类型 RabbitMQ(三)--简单模式 RabbitMQ(四)--工作队列模式 RabbitMQ(五)--发布订阅 ...

  2. 从 14 秒到 1 秒:MySQL DDL 性能优化实战

    1. 问题背景 MySQL版本:8.0.30 测试表数据量:200万 在 MySQL 中,研发人员最初执行了以下 SQL 语句,向表 t_email 中添加了一个允许为 NULL 的列 id3,并设置 ...

  3. C++ 创建进程的方法

    1. C++中创建进程的代码示例: // ProcessDemo.cpp : 此文件包含 "main" 函数.程序执行将在此处开始并结束. // #include<windo ...

  4. 为DeepSeek添加本地知识库

    为什么要尝试给DeepSeek添加本地知识库呢?作为一个程序员,以前也用过很多AI产品,直到春节DeepSeek爆火,成功在自己的电脑上把AI模型跑起来的时候才真正感受到AI已近在咫尺.未来很多应用和 ...

  5. 奥特曼autMan对接QQ机器人框架go-cqhttp的详细教程

    前言 node-onebo用pm2,screen守护都不稳定,node-onebot扫码后ctrl+c,pm2没守护直接掉了,screen只能守护几个小时.因为服务器地区与你常登q的位置不同,时常有密 ...

  6. VMware16虚拟机安装激活教程

    1.开始安装前需要准备好的软件 VMware-workstation-full-16--虚拟机软件(必要) 获取方式: 官方下载地址:https://www.vmware.com/cn/product ...

  7. 非容器环境中使用Selenium,提升Chrome与ChromeDiver兼容性

    背景 在 Windows 环境下使用 Selenium 时,Chrome 浏览器版本与 ChromeDriver 版本的兼容性问题是一个常见的困扰. 由于 Chrome 频繁更新,而 ChromeDr ...

  8. factor

    factor easy_factor1 task.py from Crypto.Util.number import * from Crypto.Util.Padding import * from ...

  9. 不上苹果的app store,安装ios应用最简单的方法

    不上架appstore,安装app有两种方法,一种是使用企业类型的苹果开发者账号的In house类型的证书和证书profile文件打包,一种是使用个人/公司类型的苹果开发者账号的ad hoc类型的证 ...

  10. mysql - 视图的操作 创建,修改,删除,查看

    只保存sql逻辑,不保存查询结果 视图可以看作是封装了多条sql语句,之后使用的时候就像普通表一样,而这个表上的字段则是创建视图时,select 后边跟的字段,支持列的别名. 创建 语法: creat ...