selenium 在centos中的配置

基本環境:centos7,python3.x
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版本對應)
wget http://chromedriver.storage.googleapis.com/2.43/chromedriver_linux64.zip
解壓此文件,並將文件移動到/usr/bin目錄下
unzip chromedriver_linx64.zip
mv chromedriver /usr/bin/

4.測試selenium是否可用,請執行以下python腳本,如返回html內容,則說明安裝成功
python3 test.py

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)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章