linux下部署selenium
1.安装chrome浏览器
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
2.安装驱动
#检查浏览器版本
google-chrome --version
#根据浏览器版本安装对应的驱动
wget https://npm.taobao.org/mirrors/chromedriver/96.0.4664.45/chromedriver_linux64.zip
yum install -y unzip zip
unzip chromedriver_linux64.zip
#添加执行权限
mv chromedriver /usr/bin/
chmod +x /usr/bin/chromedriver
chromedriver -version
脚本配置
from selenium import webdriver
# 导入包
from selenium.webdriver.chrome.options import Options
# 设置chrome浏览器无界面模式
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')
path = '/usr/bin/chromedriver'
driver = webdriver.Chrome(executable_path=path,options=chrome_options)