天天看点

记录一次ubuntu镜像中安装chrome和chromedriver

首先更新 apt-get

apt-get update
apt-get upgrade
           

一、安装Chrome浏览器

1、安装依赖

apt-get install libxss1 libappindicator1 libindicator7
           

2、下载Chrome安装包

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
           

3、安装

dpkg -i google-chrome*.deb
           
如果报错Errors were encountered while processing:  google-chrome-stable ,执行下面命令安装依赖
apt-get upgrade
apt-get update
apt -f install 
           
 然后再次执行安装命令dpkg -i google-chrome*.deb
记录一次ubuntu镜像中安装chrome和chromedriver

安装完成以后会显示安装的版本号,如上图,然后自己去找和自己浏览器同样版本号的驱动来进行下载,我的是81.0.4044,一定要和自己安装的浏览器版本相同

二、安装ChromeDriver

1、安装

xvfb

以便我们可以无头奔跑地运行Chrome

apt-get install xvfb
           

2、安装依赖

apt-get install unzip
           

3、下载安装包(https://chromedriver.storage.googleapis.com/index.html这里是下载地址,找到和自己浏览器相同版本的驱动)

wget -N http://chromedriver.storage.googleapis.com/81.0.4044.20/chromedriver_linux64.zip
           

4、解压缩+添加执行权限

unzip chromedriver_linux64.zip
           

5、移动

mv -f chromedriver /usr/local/share/chromedriver
           

6、建立软连接

ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
           

 7.配置chromedriver环境变量

vim ~/.bashrc

将自己的chromedriver加入环境变量
export PATH=$PATH:/usr/bin/chromedriver