当前位置: 首页 > news >正文

亲测可用!!!Centos7安装chrome+chromedriver以便实现selenium自动化详细教程

网上很多教程都是在线安装chrome,这样安装了最新稳定的chrome,可惜我遇到chromdriver的版本跟上 chrome,为了早日实现在centos服务selenium自动化,不可能去等待 chromdriver 更新,只能 chrome进行降版本来离线安装。花了几个小时找资源,终于找到一个可用的:

安装chrome

一、下载安装包链接: https://pan.baidu.com/s/1ScyMB54eoFfGXq7-RapsdA 提取码: amnp

二、安装流程

rpm -ivh vulkan-filesystem-1.1.97.0-1.el7.norch.rpm

rpm -ivh vulkan-1.1.97.0-1.el7.x86_64.rpm

rpm -ivh liberation-narrow-fonts-1.07.2-16.el7.noarch.rpm

rpm -ivh liberation-fonts-1.07.2-16.el7.noarch.rpm

rpm -i google-chrome-stable-current_x86_x64.rpm

chromedriver安装

chromedriver下载
在https://npm.taobao.org/mirrors/chromedriver/中下载对应版本的chromedriver,上面的chrome对应下面这个版本的:

https://cdn.npmmirror.com/binaries/chromedriver/103.0.5060.134/chromedriver_linux64.zip

解压软件:可在windows下下载, 解压后再转移过去,或unzip chromedriver_linux64.zip
将软件移至对应目录下(很重要)
mv chromedriver /usr/bin/

赋权限
chmod +x /usr/bin/chromedriver

验证安装完成
直接输入chromedriver

编写python测试chrome以及驱动是否能够正常运行

测试代码test_google.py

from selenium import webdriver
from selenium.webdriver.chrome.options import Options# 创建 ChromeOptions 实例,启用无头模式
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
# 指定 ChromeDriver 的路径(根据实际情况修改)
chrome_driver_path = '/usr/bin/chromedriver'# 创建 Chrome WebDriver 实例
driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)# 打开网页
driver.get('https://www.google.com')# 输出网页标题
print('Page title:', driver.title)# 关闭浏览器
driver.quit()

运行成功的结果

python test_google.py

/usr/path/test_google.py:13: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)
Page title: Google

http://www.lryc.cn/news/167248.html

相关文章:

  • spring cloud、gradle、父子项目、微服务框架搭建---cloud gateway(十)
  • AD22使用笔记+积累库
  • 20230912在ubuntu18.04下使用pigz来提高tar命令压缩解压缩的速度
  • python-xpath语法-爬取彼岸图4k高清动漫壁纸
  • 韩信点兵:求韩信一共有多少兵
  • 10个简单但超级有用的Python装饰器
  • DataGrip 2023 年下载、安装教程、亲测可用
  • 6.SpringEL与List,Map
  • 【Oracle】使用 SQL Developer 连接 Oracle 数据库
  • PostgreSQL 事务并发锁
  • CANoe-Model Editor无法修改ARXML文件的问题、E2E在SOME/IP通信中的使用问题
  • Conan安装第三方依赖库时SSL验证失败解决办法
  • 基于springboot+vue的大学生智能消费记账系统
  • Java——》synchronized的使用
  • vue+element使用阿里的图标库保存图标
  • Day 01 web前端基础知识
  • Redis 高可用之持久化
  • 生成元 rust解法
  • 某ERP系统存在RCE漏洞
  • ElasticSearch 因为索引字段改变,平滑迁移索引
  • invalid use of incomplete type ‘class Ui::xxx‘
  • 变压器寿命预测(python代码,Logistic Regression模型预测效果一般,可以做对比实验)
  • 微信小程序-增加隐私协议弹窗
  • 分布式事务解决方案之可靠消息最终一致性
  • ROS学习笔记(四)---使用 VScode 启动launch文件运行多个节点
  • 编译Redis时报错: jemalloc/jemalloc.h: No such file or directory
  • LLM 05-大模型法律
  • 1-5 AUTOSAR数据交换文件ARXML
  • 学习尚硅谷HTML+CSS总结
  • 自己设计CPU学习之路——基于《Xilinx FPGA应用开发》