selenium報錯解決
報錯原因如下
selenium.common.exceptions.ElementNotvisibleException: Message: element not interactable(session info: chrome=103.0.5060.114)
(Oriver info:chonedriver-108,0.50.24(eCTDO49c48c6la74dcC951011fceb276b18b10-refs /hranch-heads/560g1e212),platfonT=lindors NT 10.0.1904 x36_64)
報錯是什麼原因呢:
這報錯顯示的是自己的chromedriver的版本和谷歌浏覽器的版本不一樣
如何檢視自己的谷歌浏覽器版本
如下:
看了自己的浏覽器版本後,就要去
chromedriver下載下傳位址:
http://chromedriver.storage.googleapis.com/index.html
http://npm.taobao.org/mirrors/chromedriver/
兩個位址都可以下載下傳,根據自己的chrome浏覽器的版本選擇下載下傳即可
點進去後
進入下圖
下載下傳解壓後
把exe檔案複制到浏覽器的安裝目錄下:C:\Program Files (x86)\Google\Chrome\Application
(要根據自己實際安裝目錄)
把exe檔案複制到python的安裝目錄下:
用下面代碼,測試一下是否驅動成功
from selenium import webdriver
# 初始化driver環境
driver = webdriver.Chrome()
# 向一個url發起請求
driver.get("https://www.baidu.com/")
# 列印頁面标題
print(driver.title)
# 退出浏覽器
driver.quit() # 一定要記得退出!不然會有殘留程序
注意:浏覽器版本自動更新後,可能驅動與之不比對會報錯,如下所示:
錯誤就和上面的一樣