如何在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/')
相关推荐
Better Bench9 小时前
ubuntu20.04安全的安装可穿墙的远程软件parsec
安全·ubuntu·远程·parsec
新手村领路人10 小时前
Ubuntu18.04 libc.so.6: version `GLIBC_2.28‘ not found问题
linux·ubuntu·pycharm
lightgis10 小时前
chrome中的axure插件提示无法不受支持
前端·chrome
奥尔特星云大使12 小时前
详细的Linux系统更新yum源的教程
linux·运维·服务器·ubuntu·centos·yum源·epel源
lht63193561212 小时前
Ubuntu Server 系统安装图形界面
linux·运维·ubuntu
christine-rr12 小时前
linux常用命令(6)——网络管理
linux·服务器·网络·ubuntu·网络安全
.小墨迹16 小时前
linux删除通过源码安装的库
linux·运维·chrome
~黄夫人~16 小时前
Ubuntu系统快速上手命令(详细)
linux·运维·笔记·ubuntu·postgresql
发光的沙子16 小时前
FPGA----petalinux的Ubuntu文件系统移植
linux·运维·ubuntu
lili-felicity16 小时前
解决VMware Workstation Pro 17中Ubuntu 24.04无法复制粘贴
linux·运维·ubuntu