1、安装chrome
用下面的命令安装Google Chrome
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
也可以先下载至本地,然后安装
wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm yum install ./google-chrome-stable_current_x86_64.rpm
安装必要的库
yum install mesa-libOSMesa-devel gnu-free-sans-fonts wqy-zenhei-fonts
安装 chromedriver
1 2 3 4
| chrome官网 wget https://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip 淘宝源(推荐) wget http://npm.taobao.org/mirrors/chromedriver/2.41/chromedriver_linux64.zip
|
将下载的文件解压,放在如下位置
1 2 3 4
| unzip chromedriver_linux64.zip mv chromedriver /usr/bin/ 给予执行权限 chmod +x /usr/bin/chromedriver
|
运行代码,查看是否成功
1 2 3 4 5 6 7 8 9 10
| 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') chrome_options.add_experimental_option('excludeSwitches', ['enable-automation']) browser = webdriver.Chrome(chrome_options=chrome_options)
|