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 @ 2025-02-20 17:26  rmticocean  阅读(45)  评论(0)    收藏  举报