https://www.lgzyw.com/daily/centos/selenium-install/
先安装python3
安装相关包
yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make
准备安装python3.7,这个版本需要一个新的包libffi-devel
yum install libffi-devel -y
下载python3.7安装
wget https://www.python.org/ftp/python/3.7.3/Python-3.7.3.tar.xz
tar -xvf Python-3.7.3.tar.xz
cd Python-3.7.3
./configure prefix=/usr/local/python3
make && make install
python3软链
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
pip3 软链
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
准备安装selenium
直接使用pip3进行安装
pip3 install selenium
安装谷歌浏览器驱动
到这个页面根据系统选择要安装的版本下载并解压 http://chromedriver.storage.googleapis.com/index.html?path=2.40/
wget http://chromedriver.storage.googleapis.com/2.40/chromedriver_linux64.zip
unzip chromedriver_linux64.zip
mv chromedriver /usr/local/bin
chmod u+x,o+x /usr/local/bin/chromedriver
安装谷歌浏览器
vim /etc/yum.repos.d/google.repo
输入
[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
保存退出并执行
yum update
yum install google-chrome-stable
er
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(’–headless’)
chrome_options.add_argument(’–no-sandbox’) # 这句一定要加
#我一开始没加,就一直报‘selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally’。搞了很久。driver = webdriver.Chrome(executable_path=’/root/chromedriver’, chrome_options=chrome_options)
driver.get(‘http://py2app.readthedocs.io/en/latest/examples.html’)
print driver.title
Example setup.py templates — py2app 0.15 documentation