最新版可能出现依赖缺少又无法补充的情况
安装版本引导(针对服务器驱动不适配,可找旧版本)
https://vikyd.github.io/download-chromium-history-version/#/
下载
Linux_x64_版本号_chromedriver_linux64.zip
Linux_x64_版本号_chrome-linux.zip
解压到对应路径
测试是否能够启动服务
./chorme
启动失败一般是动态库加载不全导致的
centos可以
sudo yum install libatk-bridge*
python加载时进行路径依赖加载
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36')
chrome_options.add_argument('--disable-extensions')
chrome_options.binary_location = '/path/to/chrome' # 指定 Chrome 浏览器的路径
ser = Service()
ser.executable_path = r'/path/to/chromedriver' # 指定 ChromeDriver 的路径
# 本地环境
driver = webdriver.Chrome(service=ser, options=chrome_options)