在Linux服务器上运行selenium 爬虫

这个爬虫库基于java,所以先安装java

(CentOS8)

1
sudo dnf install java-11-openjdk-devel

如果不知道是不是安装了java,可以

1
2
java -version
javac -version

在Linux服务器上下载谷歌浏览器

1
yum install https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm

查看是否安装完毕

1
google-chrome --version
1
wget https://npm.taobao.org/mirrors/chromedriver/96.0.4664.45/chromedriver_linux64.zip 

突然发现上面连不上了,临时忽略一下证书,用这个

1
wget --no-check-certificate https://npm.taobao.org/mirrors/chromedriver/96.0.4664.45/chromedriver_linux64.zip

还是不行,到官方下载界面下载吧还是

chromedriver.storage.googleapis.com/index.html

然后会发现一大堆的版本,找到了一个96的

chromedriver.storage.googleapis.com/index.html?path=96.0.4664.45/

点进去发现有mac的linux的win的。选linux的。

把下载的zip上传到服务器上。

1
unzip chromedriver_linux64.zip

然后解压。这个当前位置最好还是一个好位置,熟悉的路径位置。

新建一个driver文件夹,然后把这个chromedriver二进制文件放进去,看起来更清晰一些

1
chmod 777 driver/chromedriver

然后给这个二进制文件一个比较好的权限。

参考

linux下部署selenium爬虫程序_谷歌爬虫工具支持linux吗-CSDN博客