linux---centos7 安装chromedriver

1.安装浏览器

指定yum 源

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

安装

curl https://intoli.com/install-google-chrome.sh | bash

ldd /opt/google/chrome/chrome | grep "not found"

 

安装后,执行:google-chrome-stable --no-sandbox --headless --disable-gpu --screenshot https://www.baidu.com/

报这个错误?我猜想是没有UI界面的原因,到这里可以判断安装成功。

2. 安装chromedriver

下载:https://npm.taobao.org/mirrors/chromedriver/

unzip 解压

安装完成

 建立软连接:

ln -s /opt/google/chromedriver /usr/bin/chromedriver

 3.测试:

#coding=utf8
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
driver = webdriver.Chrome(chrome_options=chrome_options)
#driver = webdriver.Chrome()
driver.get("https://www.baidu.com")

print(driver.page_source)
#driver.quit()

到这里ok

 

posted @ 2018-08-09 17:02  myvic  阅读(9370)  评论(1编辑  收藏  举报