海南網(wǎng)站備案百度一下你就知道官網(wǎng)新聞
WebDriver以原生的方式驅(qū)動瀏覽器,不需要調(diào)整環(huán)境變量。
一、window版
1.chrome和chromedriver下載地址:
Chrome for Testing availability
我下載的是如下兩個安裝包,解壓即可。
2.導包
pip install selenium
然后用python代碼引用即可
二、Linux版
1.chrome和chromedriver下載地址:Chrome for Testing availability
操作步驟:
#chrome
unzip chrome-linux64.zip
sudo mv chrome-linux64 /opt/google-chrome
sudo ln -s /opt/google-chrome/chrome /usr/bin/google-chrome
#通過在終端中輸入 google-chrome 來運行 Chrome#chromdriver
unzip chromedriver-linux64.zip
sudo mv chromedriver-linux64/chromedriver /usr/local/bin/
sudo chmod +x /usr/local/bin/chromedriver#使用方法
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Optionsdef get_webdriver():options = Options()options.add_argument("--headless") # 如果需要無頭模式service = Service('/usr/local/bin/chromedriver')return webdriver.Chrome(service=service, options=options)# 使用 WebDriver
driver = get_webdriver()
driver.get('https://www.example.com')
print(driver.title)
driver.quit()
查看版本看是否匹配:
chromedriver --version
google-chrome --version