亲测可用!!!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

相关推荐
weixin_3077791336 分钟前
在Linux服务器上使用Jenkins和Poetry实现Python项目自动化
linux·开发语言·python·自动化·jenkins
念念不忘 必有回响3 小时前
前端自动化部署全流程(Jenkins + Nginx)
前端·自动化·jenkins
老坛程序员3 小时前
Coze 与 n8n 深度对比:AI智能体平台与工作流自动化的核心博弈
运维·人工智能·自动化
总有刁民想爱朕ha3 小时前
Python自动化从入门到实战(24)如何高效的备份mysql数据库,数据备份datadir目录直接复制可行吗?一篇给小白的完全指南
数据库·python·自动化·mysql数据库备份
西欧伯爵16 小时前
Playwright自动化实战一
自动化测试·自动化·playwright
lightgis17 小时前
chrome中的axure插件提示无法不受支持
前端·chrome
霍格沃兹软件测试开发1 天前
借助 Dify 实现自动化工作流,每天节省3小时
运维·ai·自动化
星空的资源小屋1 天前
RoboIntern,一款自动化办公小助手
运维·人工智能·pdf·自动化·电脑·excel
.小墨迹1 天前
linux删除通过源码安装的库
linux·运维·chrome
Allen_LVyingbo1 天前
2025年10月版集成RagFlow和Dify的医疗知识库自动化查询(安装篇)
运维·信息可视化·自动化·健康医疗