步驟
1.python安裝selenium
pip install selenium
2.下載安裝chrome和Chromedriver
注意:兩者大版本號(hào)要保持一致震放。例如拧略,我的谷歌瀏覽器版本117.+产园,那么Chromedriver也需要117.+才行延赌。
[圖片上傳失敗...(image-461a41-1700208521836)]
Chromedriver下載地址:
Chromedriver版本(版本<=114)
下載地址(選擇自己需要的版本):http://chromedriver.storage.googleapis.com/index.html
Chromedriver更高版本(117<=版本<=119):點(diǎn)我跳轉(zhuǎn)
或:https://googlechromelabs.github.io/chrome-for-testing/#stable
3.安裝Chromedriver
Mac:
安裝Chromedrive
將下載好的可執(zhí)行文件移動(dòng)到/usr/local/bin目錄中焕毫;
在Mac終端輸入:sudo mv chromedriver /usr/local/bin
4.測(cè)試Chromedrive是否可用
寫一個(gè).py文件癣丧,用以下代碼測(cè)試肥败,如果能成功打開谷歌瀏覽器族跛,跳轉(zhuǎn)到百度烤芦,3秒后自動(dòng)關(guān)閉举娩。即Chromedrive是可用的。
from selenium import webdriver
wd = webdriver.Chrome()
wd.get("https://www.baidu.com") # 打開百度瀏覽器
time.sleep(3) #等待3秒
wd.quit() #關(guān)閉瀏覽器
Python+Selenium基礎(chǔ)入門及實(shí)踐(http://www.reibang.com/p/1531e12f8852)