1. 安装chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
2. 安装chromedriver
wget https://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
# 或者
wget http://npm.taobao.org/mirrors/chromedriver/2.41/chromedriver_linux64.zip
3. 装好之后就地解压:
unzip chromedriver_linux64.zip
4. 然后将解压的chromedriver移动到 /usr/bin目录下:
mv chromedriver /usr/bin/
5. 给与执行权限:
chmod +x /usr/bin/chromedriver
6. 检查版本:
# 检查 chromedriver驱动 版本
chromedriver -version
#检查 chrome 版本
google-chrome --version
7. 完善py文件中的 Chrome 启动参数如下:
目测防止报错:如
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location /usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=2.41.578700 (2f1ed5f9343c13f73144538f15c00b370eda6706),platform=Linux 4.18.0-147.5.1.el8_1.x86_64 x86_64)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--disable-dev-shm-usage')