Alibaba Cloud Linux成功执行selenium、chrome-headless-shell
操作系统:Alibaba Cloud Linux 3.2104 LTS 64位 UEFI版
进入
Chrome for Testing availability
找到 chrome-headless-shell linux64 以及 chromedriver linux64
一、下载 chrome-headless-shell
# 下载并解压
wget https://storage.googleapis.com/chrome-for-testing-public/132.0.6834.110/linux64/chrome-headless-shell-linux64.zip
unzip chrome-headless-shell-linux64.zip
# 移动到系统路径(例如 /opt)
sudo mv chrome-headless-shell-linux64 /opt/chrome-headless-shell
二、下载匹配的 chromedriver
wget https://storage.googleapis.com/chrome-for-testing-public/132.0.6834.110/linux64/chromedriver-linux64.zip
unzip chromedriver-linux64.zip
cd chromedriver-linux64
sudo mv chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver
cd ..
rm -rf chromedriver-linux64
三、安装依赖库
# 如果报错缺少库(如 libnss3),安装基础依赖
sudo yum install -y atk gtk3 cups-libs libXcomposite libXcursor libXdamage libXext libXi libXtst libxkbcommon pango gtk3 nss alsa-lib
四、修改 Python 脚本
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument('--headless') # 明确启用无头模式(部分版本可能需要)
options.add_argument('--no-sandbox')
# 指定 chrome-headless-shell 路径
options.binary_location = '/opt/chrome-headless-shell/chrome-headless-shell'
driver = webdriver.Chrome(
executable_path='/usr/local/bin/chromedriver',
options=options
)
driver.get('https://www.baidu.com')
print(driver.title)
driver.quit()
五、执行成功
————————————————
原文链接:https://blog.csdn.net/def_2/article/details/145355890
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律