CentOS安装python3.x最新版和chrome chromedriver

之前使用selenium-wire的响应拦截器获取请求头中的签名需要部署到服务器,所以得搭建一个服务器运行环境,安装过程有坑,这里记录一下。

Linux平台安装需要下载源码包自己编译,下载地址:https://www.python.org/downloads/source/

选择稳定版的tgz包下载,可以本机下载然后传到服务器比较快一点。

因为selenium-wire这个包使用了ssl功能,服务器yum安装的openssl版本不满足需求,需要先下载openssl源码包,编译安装。如果不安装openssl执行python脚本时可能会出现“No module named _ssl”,参考下面地址安装

https://www.jianshu.com/p/3ec24f563b81

openssl下载地址:https://www.openssl.org/source/

openssl-1.1.1s.tar.gz

#安装编译python需要的包
$ yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel gcc
# 安装openssl
$ tar -zxvf openssl-1.1.1s.tar.gz
$ cd openssl-1.1.1s
$ ./config --prefix=$HOME/openssl shared zlib
$ make && make install
$ echo "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$HOME/openssl/lib" >> $HOME/.bash_profile
$ source $HOME/.bash_profile
# 安装Python
$ tar -zxvf Python-3.11.1.tgz
$ cd Python-3.11.1
$ mkdir -p /usr/local/python3
$ ./configure --prefix=/usr/local/python3 --with-openssl=$HOME/openssl
$ make && make install
# 安装chromedriver
$ wget https://chromedriver.storage.googleapis.com/108.0.5359.71/chromedriver_linux64.zip
$ unzip chromedriver_linux64.zip 
$ mv chromedriver /usr/local/bin/
$ chromedriver -V
# 安装linux chrome
$ wget --no-check-certificate https://intoli.com/install-google-chrome.sh
$ chmod +x install-google-chrome.sh
$ ./install-google-chrome.sh 
$ google-chrome --version

# 安装我们的python脚本需要的包,执行我们的python脚本测试
$ /usr/local/python3/bin/pip3 install -r requirements.txt
$ /usr/local/python3/bin/python3 /data/spider/test.py

一些问题解决参考:

centos 解决python3.7 安装时No module named _ssl

PIP 源 至清华、阿里镜像

linux下无界面环境安装并使用chrome,chromedriver,selenium进行爬虫设计

selenium-wire

解决报错libssl.so.1.1: cannot open shared object file: No such file or directory

unknown error: DevToolsActivePort file doesn't exist

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值