新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
配置Python3+selenium時(shí)常遇到的錯(cuò)誤
本篇文章重點(diǎn)為大家講解一下配置Python3+selenium時(shí)常遇到的錯(cuò)誤,有需要的小伙伴可以參考一下。

第一個(gè)坑:’geckodriver’ executable needs to be in PATH
1.如果啟動(dòng)瀏覽器過程中報(bào)如下錯(cuò)誤
Traceback (most recent call last):
File "", line 1, in
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 "", line 1, in
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 "", line 1, in
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: 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的安裝目錄下
新聞名稱:配置Python3+selenium時(shí)常遇到的錯(cuò)誤
網(wǎng)站網(wǎng)址:http://m.5511xx.com/article/djpohgh.html


咨詢
建站咨詢
