之前使用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