系统环境
[root@xxx ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@xxx ~]# python3.6 --version
Python 3.6.8
1、安装chromium
yum -y install epel-release
yum -y install chromium
chromium-browser --version #查看版本
2、安装chromedriver(在http://chromedriver.storage.googleapis.com/index.html根据你安装的chrome版本查找)
cd /usr/local/src/
wget -c http://chromedriver.storage.googleapis.com/79.0.3945.36/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver /usr/bin/
3、写python脚本测试下(脚本文件名test.selenium.py,内容如下)
import time
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome( \
chrome_options=chrome_options, \
service_args=['--verbose', '--log-path=chromedriver.log'])
driver.get("https://www.google.com/")
time.sleep(1)
print(driver.current_url)
cookie = driver.get_cookies()
print(cookie)
driver.quit()
4、执行测试
python3 test.selenium.py
参考文章:
selenium 配置 chromedriver
Python Selenium - 在无图形Linux机器上使用selenium的几种方案