gpt4 book ai didi

启动 Firefox 时出现 python webdriver 错误

转载 作者:太空狗 更新时间:2023-10-30 02:17:33 25 4
gpt4 key购买 nike

我最近下载了 selenium 并尝试运行这个脚本:

 from selenium import webdriver
driver = webdriver.Firefox()

但是我得到这个错误:

Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
driver = webdriver.Firefox()
File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\firefox\webdriver.py", line 145, in __init__
keep_alive=True)
File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Heights\PortableApps\PortablePython2.7.6.1\App\lib\site-packages\selenium-3.0.1-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'firefox_binary' capability provided, and no binary flag set on the command line

哦,顺便说一句,这会在打印错误之前打开我的 geckodriver.exe

最佳答案

我通过按照以下答案手动设置二进制位置来解决这个问题:

https://stackoverflow.com/a/25715497

请记住将您的二进制文件设置为计算机上 firefox 二进制文件的实际位置

例如:

from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary(r'C:\Program Files (x86)\Mozilla Firefox\firefox.exe')
self.browser = webdriver.Firefox(firefox_binary=binary)

(注意:文件路径字符串中第一个引号前的 'r' 使 python 将该字符串视为 '原始' 文本,因此您不需要转义像 '\' 这样的字符 - 您只需输入实际路径)

关于启动 Firefox 时出现 python webdriver 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40057725/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com