#下载Chrome
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
#安装依赖包
yum install -y lsb
yum install -y libXScrnSaver
yum install at-spi2-atk
yum install liberation-fonts
yum install gtk3
yum -y install vulkan-1.1.97.0-1.el7.x86_64
安装chrome
rpm -ivh google-chrome-stable_current_x86_64.rpm
查看安装目录,测试是否安装成功
[root@localhost ~]# which google-chrome-stable /usr/bin/google-chrome-stable [root@localhost ~]# [root@localhost ~]# /usr/bin/google-chrome-stable --no-sandbox flag [39639:39639:0212/182910.753569:ERROR:browser_main_loop.cc(1438)] Unable to open X display. [root@localhost ~]# [0212/182910.765694:ERROR:nacl_helper_linux.cc(307)] NaCl helper process running without a sandbox! Most likely you need to configure your SUID sandbox correctly ^C [root@localhost ~]#
#下载Chrome驱动
wget http://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
#解压
unzip chromedriver_linux64.zip
#将驱动文件移动到 /bin 目录中
mv chromedriver /bin/
#加执行权限
chmod +x /bin/chromedriver
#设置环境变量vi ~/.bash_profile
PATH=$PATH:/bin/chromedriver
export PATH
#使生效
source ~/.bash_profile
#测试代码
import sys,os
from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
option = webdriver.ChromeOptions()
option.add_argument(‘--no-sandbox‘)
option.add_argument(‘--headless‘)
driver = webdriver.Chrome(options=option)
driver.get("https://www.baidu.com/")
print(driver.title)
driver.quit()
#运行效果
[root@localhost ~]# python3 test.py
百度一下,你就知道
[root@localhost ~]#
centos7 selenium headless模式环境搭建
原文:https://www.cnblogs.com/sea-stream/p/14399132.html