Python3+selenium配置常見報(bào)錯(cuò)解決方案
第一個(gè)坑:'geckodriver' executable needs to be in PATH
1.如果啟動(dòng)瀏覽器過程中報(bào)如下錯(cuò)誤
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 145, in __init__
self.service.start()
File "D:\test\python3\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
2.這個(gè)是因?yàn)樽钚碌膕elenium3.0啟動(dòng)firefox需要geckodriver.exe這個(gè)驅(qū)動(dòng)文件。
3.下載之后,配置到環(huán)境變量path下(可以直接放python根目錄)
第二坑:Expected browser binary location, but unable to find binary in default location
1.如果啟動(dòng)瀏覽器過程中報(bào)如下錯(cuò)誤:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
keep_alive=True)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Expected browser binary location, but unable to find binary in default location,
no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line.
2.這個(gè)是因?yàn)閒irefox.exe這個(gè)文件也需要配置到環(huán)境變量path下。
3.這個(gè)路徑就是安裝完firefox后,找到firefox.exe這個(gè)文件的地址,加到path下。
第三坑:Unsupported Marionette protocol version 2, required 3
1.如果啟動(dòng)瀏覽器過程中出現(xiàn)如下錯(cuò)誤
Traceback (most recent call last):
File "<stdin>", line 1, in <module>File "D:\test\python3\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 155, in __init__
keep_alive=True)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "D:\test\python3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_responseraise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unsupported Marionette protocol version 2, required 3
2.這個(gè)錯(cuò)誤原因是firefox版本過低了,最新的selenium3.0版本支持firefox47以上的版本,升級版本就可以了
第四坑:WebDriverException: Message: newSession
1.Traceback (most recent call last):
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 170, in init
keep_alive=True)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 156, in init
self.start_session(capabilities, browser_profile)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 245, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\webdriver.py”, line 314, in execute
self.error_handler.check_response(response)
File “D:\test\python3\lib\site-packages\selenium\webdriver\firefox\\errorhandler.py”, line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: newSession
2.下載最新的geckodriver.exe 然后把它放到python的安裝目錄下
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
入門tensorflow教程之TensorBoard可視化模型訓(xùn)練
在本篇文章中,主要介紹 了TensorBoard 的基礎(chǔ)知識(shí),并了解如何可視化訓(xùn)練模型中的一些基本信息,希望對大家的TensorBoard可視化模型訓(xùn)練有所幫助2021-08-08
Linux上Miniconda的安裝的實(shí)現(xiàn)步驟
Miniconda是一個(gè)輕量級、免費(fèi)且開源的跨平臺(tái)軟件包管理系統(tǒng),本文主要介紹了Linux上Miniconda的安裝的實(shí)現(xiàn)步驟,具有一定的參考價(jià)值,感興趣的可以了解一下2024-03-03
基于Python實(shí)現(xiàn)定時(shí)自動(dòng)給微信好友發(fā)送天氣預(yù)報(bào)
這篇文章主要介紹了基于Python實(shí)現(xiàn)定時(shí)自動(dòng)給微信好友發(fā)送天氣預(yù)報(bào)的實(shí)現(xiàn)代碼,,需要的朋友可以參考下2018-10-10
Python+Selenium定位不到元素常見原因及解決辦法(報(bào):NoSuchElementException)
這篇文章主要介紹了Python+Selenium定位不到元素常見原因及解決辦法(報(bào):NoSuchElementException),文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-03-03
關(guān)于Python中的 oct 函數(shù)與 min 函數(shù)
本文主要介紹了Python oct 函數(shù)與 min 函數(shù);oct 函數(shù)是 Python 內(nèi)置函數(shù),主要將一個(gè)整數(shù)轉(zhuǎn)為八進(jìn)制,與 ord 函數(shù) / chr 函數(shù) 有點(diǎn)類似;min 函數(shù)返回給定參數(shù)的最小值,參數(shù)可以為序列語法,感興趣的小伙伴請繼續(xù)閱讀下文2021-09-09
使用python和opencv的mask實(shí)現(xiàn)摳圖疊加
這篇文章主要介紹了使用python和opencv的mask實(shí)現(xiàn)摳圖疊加操作,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2021-04-04
詳解如何使用Pandas刪除DataFrame中的非數(shù)字類型數(shù)據(jù)
在數(shù)據(jù)處理和分析過程中,經(jīng)常會(huì)遇到需要清洗數(shù)據(jù)的情況,本文將詳細(xì)介紹如何使用Pandas刪除DataFrame中的非數(shù)字類型數(shù)據(jù),感興趣的小伙伴可以了解下2024-03-03

