首先安装必备工具
安装vim
yum -y install vim*
安装zip
yum -y install zlib*
安装rz
yum install lrzsz
1.安装python3
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.4.tgz
tar -xvzf Python-3.6.4.tgz
cd Python-3.6.4
./configure --prefix=/usr/local/python3
yum -y install zlib*
make && make install
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
安装python包
pip3 install selenium
如果缺少ssl认证
查看openssl安装包,发现缺少openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5
[root@localhost ~]#
yum安装openssl-devel
[root@localhost ~]# yum install openssl-devel -y
查看安装结果
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-26.el5_9.1
openssl-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
重新编译python
修改Setup文件
[root@localhost ~]# cd ~/Python-3.6.5
vim Modules/Setup
修改成下面:
通过输入:/_ssl 快速查找到定位到以下内容(备注)
...# Socket module helper for socket(2)
..._socket socketmodule.c timemodule.c #去除该行注释(备注)
...# Socket module helper for SSL support; you must comment out the other
...# socket line above, and possibly edit the SSL variable:
...#SSL=/usr/local/ssl
..._ssl _ssl.c \ #去除该行注释(备注)
...-duse_ssl -I(ssl)/include/openssl \ #去除该行注释(备注)
...-l$(ssl)/lib -lssl -lcrypto #去除该行注释(备注)
重新编译(回到python安装包路径下)
[root@localhost ~]# cd ~
[root@localhost ~]# cd Python-3.6.5
make
make install
2.安装chrome浏览器
https://blog.csdn.net/u010472499/article/details/72327963
配置yum源
cd /ect/yum.repos.d/
vim google-chrome.repo
写入如下内容:
[google-chrome]
name=google-chrome
baseurl=http://dl.google.com/linux/chrome/rpm/stable/$basearch
enabled=1
gpgcheck=1
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub
yum -y install google-chrome-stable --nogpgcheck
which google-chrome-stable
ln -s xxx /bin/chrome
备注:ln -s /usr/bin/google-chrome-stable /bin/chrome
注意:Chrome不能以root用户运行,需要添加将启动方式修改为沙盒。修改启动参数:
vim /usr/bin/google-chrome
在exec -a "HERE/chrome" "0" "@" --no-sandbox --user-data-dir
备注链接https://blog.csdn.net/sunny05296/article/details/79265654
3.部署Xvfb 无界面使用chrome
yum update
yum install Xvfb
yum install libXfont
yum install xorg-x11-fonts*
4.安装webdriver
google-chrome -version # 查看 chrome 版本
https://blog.csdn.net/huilan_same/article/details/51896672
webdriver源
http://chromedriver.storage.googleapis.com/index.html
http://npm.taobao.org/mirrors/chromedriver/
备注google-chrome 是67 webdriver安装2.38
wget -N http://chromedriver.storage.googleapis.com/2.38/chromedriver_linux64.zip
yum install unzip
unzip chromedriver_linux64.zip
chmod +x chromedriver
sudo mv -f chromedriver /usr/local/share/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
sudo ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
google-chrome -version
which google-chrome-stable
5.启动Xvfb服务
Xvfb -ac :7 -screen 0 1280x1024x8
6.启动chrome
另开一个窗口
ps -aux|grep Xvfb
export DISPLAY=:7
/usr/bin/google-chrome-stable http://www.baidu.com