centos7安装python3+selenium+chrome

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值