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

posted @   rmticocean  阅读(13)  评论(0编辑  收藏  举报
编辑推荐:
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示