centos install chromedriver

简介:

运行微博爬虫始终提示

'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/ch

试图通过yum –y install chromedriver阿里云匹配的chromedriver的版本低于chrome,需要更新。然后发现不管是更新chrome还是chromium,始终都存在着版本不对。直到找到了这个:

https://blog.csdn.net/herobacking/article/details/80276060

安装 chrome

使用下面的命令,在root用户下就可以安装最新的 Google Chrome:

yum –y install google-chrome-stable

安装 selenium

在 seleniump官网 找到最新的版本,下载selenium-server-standalone-X.XX.X.jar文件

selenium-server-standalone-3.13.0.jar

selenium服务初始化

将上述selenium放入一个文件夹中,输入如下命令初始化

java -jar selenium-server-standalone-3.13.0.jar

注意,需要 java8 环境,可以参考 CentOS7安装java运行环境jdk

安装 chromerriver

在 chromerriver官网下载最新的ChromeDriver压缩包,解压得到chromedriver.exe文件

chromedriver_linux64.zip

将下载的文件解压,放在如下位置

/usr/bin/chromedriver

给予执行权限

chmod +x /usr/bin/chromedriver

安装 XVFB

输入如下命令

yum install Xvfb -y 

yum install xorg-x11-fonts* -y

新建在/usr/bin/ 一个名叫 xvfb-chrom 的文件写入以下内容:

vi /usr/bin/xvfb-chrome

#!/bin/bash 

 

_kill_procs() { 

  kill -TERM $chrome 

  wait $chrome 

  kill -TERM $xvfb 

 

# Setup a trap to catch SIGTERM and relay it to child processes 

trap _kill_procs SIGTERM 

 

XVFB_WHD=${XVFB_WHD:-1280x720x16} 

 

# Start Xvfb 

Xvfb :99 -ac -screen 0 $XVFB_WHD -nolisten tcp & 

xvfb=$! 

 

export DISPLAY=:99 

 

chrome --no-sandbox --disable-gpu$@ & 

chrome=$! 

 

wait $chrome 

wait $xvfb

添加执行权限

chmod +x /usr/bin/xvfb-chrome

查看当前映射关系

ll /usr/bin/ | grep chrom

-rwxr-xr-x   1 root root   7874704 Mar 20 14:55 chromedriver

lrwxrwxrwx   1 root root        31 Mar 20 00:24 google-chrome -> /etc/alternatives/google-chrome

lrwxrwxrwx   1 root root        32 Mar 20 14:30 google-chrome-stable -> /opt/google/chrome/google-chrome

更改Chrome启动的软连接

ln -s /etc/alternatives/google-chrome /usr/bin/chrome 

rm -rf /usr/bin/google-chrome

ln -s /usr/bin/xvfb-chrome /usr/bin/google-chrome

查看修改后的映射关系

ll /usr/bin/ | grep chrom

-rwxr-xr-x   1 root root   chromedriver

lrwxrwxrwx   1 root root        chrome -> /etc/alternatives/google-chrome

lrwxrwxrwx   1 root root        google-chrome -> /usr/bin/xvfb-chromium

lrwxrwxrwx   1 root root        google-chrome-stable -> /opt/google/chrome/google-chrome

-rwxr-xr-x   1 root root       xvfb-chrome

 

目录
相关文章
|
8天前
|
Linux Shell Python
centos执行pip3 install etcd3报错
centos执行pip3 install etcd3报错
|
3月前
|
关系型数据库 MySQL Linux
Linux部署实战前言,MySQL在CentOS安装【单机软件】,MySQL的安装需要root权限,yum install mysql,systemctl enable mysqld开机自启的意思
Linux部署实战前言,MySQL在CentOS安装【单机软件】,MySQL的安装需要root权限,yum install mysql,systemctl enable mysqld开机自启的意思
|
5月前
|
Linux Docker 容器
CentOS7 Install Docker Compose
CentOS7 Install Docker Compose
129 0
|
缓存 网络协议 Linux
CentOS8 yum install 报错Cannot prepare internal mirrorlist: No URLs in mirrorlist解决(替换yum源)
CentOS8 yum install 报错Cannot prepare internal mirrorlist: No URLs in mirrorlist解决(替换yum源)
CentOS8 yum install 报错Cannot prepare internal mirrorlist: No URLs in mirrorlist解决(替换yum源)
|
Linux Docker 容器
|
Web App开发 数据采集 Dubbo
CentOS 6.x 搭建:Headless Chrome + ChromeDriver + Selenium基于浏览器的爬虫环境
Headless Chrome 是 Chrome 浏览器的无界面形态,可以在不打开浏览器的前提下,使用所有 Chrome 支持的特性运行你的程序。相比于现代浏览器,Headless Chrome 更加方便测试 web 应用,获得网站的截图,做爬虫抓取信息等。相比于出道较早的 PhantomJS,SlimerJS 等,Headless Chrome 则更加贴近浏览器环境。
1586 0
|
Linux
Centos下pip3 install pycrypto安装失败的解决办法
Centos下pip3 install pycrypto安装失败的解决办法
1557 0
Centos下pip3 install pycrypto安装失败的解决办法
|
弹性计算 关系型数据库 Linux
How to Install CMS Made Simple v2.2 on LAMP in CentOS 7.2
In this tutorial, we will be setting up CMS Made Simple on a LAMP stack with an Alibaba Cloud ECS instance (CentOS 7.2).
3903 0
How to Install CMS Made Simple v2.2 on LAMP in CentOS 7.2
|
弹性计算 网络协议 Linux
How to Install and Configure Docker Swarm Mode on CentOS 7
In this tutorial, we will learn how to set up Docker Swarm on an Alibaba Cloud ECS CentOS 7 instance.
2142 0
How to Install and Configure Docker Swarm Mode on CentOS 7
|
Web App开发 关系型数据库 PHP
Install WordPress on Centos
Before beginning, a domain, an ESC or a VPS is needed. Once the ECS or the VPS and the domain are prepared, the following procedures can be conducted.
1106 0
下一篇
无影云桌面