Linux 使用 selenium 环境配置

1、需要安装 Chrome 浏览器

yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

2、安装必要库

yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts

3、安装驱动

(1)查看版本号

google-chrome --version

(2)去淘宝源找寻对应的文件

http://npm.taobao.org/mirrors/chromedriver/

(3)找到后,下载

wget http://npm.taobao.org/mirrors/chromedriver/90.0.4430.24/chromedriver_linux64.zip

(4)解压,赋权

unzip chromedriver_linux64.zip

mv chromedriver /usr/bin/

cd /usr/bin

chmod chromedriver+x /usr/bin/

(5)验证

python3

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
chrome_options.add_argument('--headless')
browser = webdriver.Chrome(options=chrome_options)
 
'''
其他提高性能参数
'''
chrome_options.add_argument('blink-settings=imagesEnabled=false')
chrome_options.add_argument('--disable-gpu')

# “–no-sandbox”参数是让Chrome在root权限下跑
# “–headless”参数是不用打开图形界面
原文地址:https://www.cnblogs.com/yebaofang/p/14706134.html