如何在Ubuntu上部署最新的Google Chrome和ChromeDriver

本章将帮助各位同学如何在Ubuntu及衍生版安装ChromeDriver和Selenium。

准备

执行以下命令以在系统上安装所需的软件包。这里 Xvfb(X 虚拟帧缓冲区)是用于类 UNIX 操作系统(例如 Linux)的内存显示服务器。它实现了没有任何显示的 X11 显示服务器协议。这对于 CI 服务等 CLI 应用程序很有帮助。

ruby 复制代码
$ sudo apt update 
$ sudo apt install -y unzip xvfb libxi6 libgconf-2-4 

安装 Chrome

ruby 复制代码
$ sudo curl -sS -o - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add 
$ sudo bash -c "echo 'deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main' >> /etc/apt/sources.list.d/google-chrome.list" 
$ sudo apt -y update 
$ sudo apt -y install google-chrome-stable 

安装 ChromeDriver

查看 Chrome版本

css 复制代码
$ google-chrome --version 
Google Chrome 122.0.6261.111

官网只有115及以下的支持版本 我找到一个文件可以找到最新版的 ChromeDriver。通过Wget、curl或aria2下载chromedriver_linux64.zip

解压

python 复制代码
$ unzip chromedriver_linux64.zip 

部署

shell 复制代码
$ sudo mv chromedriver /usr/bin/chromedriver 
$ sudo chown root:root /usr/bin/chromedriver 
$ sudo chmod +x /usr/bin/chromedriver 

Python selenium

代码

javascript 复制代码
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

service = Service(executable_path='/usr/bin/chromedriver')
options = Options()
options.add_argument("--no-sandbox")
options.add_argument("--headless")
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1920,1080")
driver = webdriver.Chrome(service=service, options=options)

driver.get('https://www.python.org/')
相关推荐
海兰6 小时前
云原生持续交付平台 Zadig 在 Ubuntu 24.04 上的部署及使用指南
linux·ubuntu·云原生
Anesthesia丶8 小时前
PromoxVE安装笔记
笔记·ubuntu·server·promox
常乐か21 小时前
VMware Workstation Pro 17 搭建 Ubuntu 24.04 完整指南
linux·运维·ubuntu
PGCCC1 天前
Ubuntu 安装 PostgreSQL 16 完整教程(2026):从仓库配置到远程连接
linux·ubuntu·postgresql
常乐か1 天前
在 Ubuntu 24.04 中编译 Qt 5.15.2 项目完全指南
linux·qt·ubuntu
hello_fengfeng1 天前
fcitx4 和 fcitx5 输入法包冲突
ubuntu
我是小灰灰吖1 天前
Ubuntu 22.04 切换为 X11 会话以解决 QT 桌面程序兼容性问题
linux·qt·ubuntu
鬼手点金1 天前
Hermes‑Agent 使用教程
python·ubuntu·powershell·cmd·ai agent·opencode·hermes
桑榆4161 天前
WebRTC 本地视频文件推流 Demo 搭建指南 (Ubuntu 24.04)
linux·ubuntu·webrtc