首先安裝必備工具
安裝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認(rèn)證
查看openssl安裝包,發(fā)現(xiàn)缺少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
查看安裝結(jié)果
[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 快速查找到定位到以下內(nèi)容(備注)
...# 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
寫入如下內(nèi)容:
[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用戶運(yùn)行,需要添加將啟動(dòng)方式修改為沙盒。修改啟動(dòng)參數(shù):
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.啟動(dòng)Xvfb服務(wù)
Xvfb -ac :7 -screen 0 1280x1024x8
6.啟動(dòng)chrome
另開一個(gè)窗口
ps -aux|grep Xvfb
export DISPLAY=:7
/usr/bin/google-chrome-stable http://www.baidu.com