centos 安裝python環(huán)境-chrome,webdriver,selenium

首先安裝必備工具

安裝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 -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 "0" "HERE/chrome" "@"后他添加如下內(nèi)容: --no-sandbox --user-data-dir 添加后的結(jié)果: exec -a "0" "HERE/chrome" "@" --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

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容