pip3 install seleniumhtml
wget https://dl.google.com/linux/d... --no-check-certificate python
yum install ./google-chrome-stable_current_x86_64.rpmlinux
1254109F0E439D718CC399416C7238D3.pngweb
因爲下載的chrome-browser是70版本的,因此chromedriver 選擇了2.43版本chrome
wget http://chromedriver.storage.g...centos
解壓此文件,並將文件移動到/usr/bin目錄下python3.x
unzip chromedriver_linx64.zipapi
mv chromedriver /usr/bin/less
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)
注意須要加上,禁止在沙箱中運行測試
option.add_argument('--no-sandbox')
option.add_argument('--headless')
安裝firefox支持
yum install firefox
yum install Xvfb
yum install libXfont
pip3 install pyvirtualdisplay
測試腳本
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()