Python3 + selenium + Chrome瀏覽器
Error:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH.Please see https://sites.google.com/a/chromium.org/chromedriver/home
這是因為調用 webdriver.Chrome() 需要設置參數 executable_path,而executable_path 為chromedriver.exe所在地址。
chromedriver.exe的下載地址為 http://chromedriver.storage.googleapis.com/index.html
首先需要確定本機的Chrome瀏覽器的版本,在Chrome瀏覽器里輸入"chrome://version"即可,如下圖,Google Chrome冒號后面即為對應版本。本機的Chrome版本為75.0.3770.142,下載地址中並無完全吻合的版本,最后下載了75.0.3770.142版本對應的亦可兼容本機。
這是下載地址界面:
然后我們轉到對應版本界面,選擇對應系統的zip文件下載並解壓。
得到chromedriver.exe文件后,給 webdriver.Chrome() 添加參數 executable_path = 'path/chromedriver.exe'(path為chromedriver.exe所在的目錄)
之后我的代碼就運行成功了