web自動(dòng)化爬蟲seleniumcentos無GUI環(huán)境配置

基本環(huán)境:centos7,python3.x

創(chuàng)新互聯(lián)專注于企業(yè)成都全網(wǎng)營銷、網(wǎng)站重做改版、建平網(wǎng)站定制設(shè)計(jì)、自適應(yīng)品牌網(wǎng)站建設(shè)、H5頁面制作、商城網(wǎng)站建設(shè)、集團(tuán)公司官網(wǎng)建設(shè)、外貿(mào)網(wǎng)站制作、高端網(wǎng)站制作、響應(yīng)式網(wǎng)頁設(shè)計(jì)等建站業(yè)務(wù),價(jià)格優(yōu)惠性價(jià)比高,為建平等各大城市提供網(wǎng)站開發(fā)制作服務(wù)。

1.安裝selenium

pip3 install selenium

2.安裝chrome-browser

wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm --no-check-certificate  

yum install ./google-chrome-stable_current_x86_64.rpm

3.下載chromedriver(注意要和chrome-browser版本對應(yīng))

web自動(dòng)化爬蟲selenium centos 無GUI環(huán)境配置

由于下載的chrome-browser是70版本的,所以chromedriver 選擇了2.43版本

wget http://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip

解壓此文件,并將文件移動(dòng)到/usr/bin目錄下

unzip chromedriver_linx64.zip

mv chromedriver /usr/bin/

4.測試selenium是否可用,請執(zhí)行以下python腳本,如返回html內(nèi)容,則說明安裝成功

from selenium import webdriver
url='http://bing.com'
option = webdriver.ChromeOptions()
option.add_argument('--no-sandbox')
option.add_argument('--headless')
driver = webdriver.Chrome(chrome_options=option)
driver.get(url)
print(driver.page_source)

注意需要加上,禁止在沙箱中運(yùn)行

option.add_argument('--no-sandbox')
option.add_argument('--headless')

補(bǔ)充:

安裝firefox支持

yum install firefox

yum install Xvfb

yum install libXfont

pip3 install pyvirtualdisplay

測試腳本

#!/usr/bin/python3
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800,600))
display.start()
driver = webdriver.Firefox()
driver.get('https://www.baidu.com')
print(driver.title)
driver.quit()
display.stop()

當(dāng)前題目:web自動(dòng)化爬蟲seleniumcentos無GUI環(huán)境配置
轉(zhuǎn)載源于:http://bm7419.com/article0/jcedio.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作網(wǎng)站維護(hù)、軟件開發(fā)、網(wǎng)站內(nèi)鏈、品牌網(wǎng)站設(shè)計(jì)、網(wǎng)站收錄

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化