我在尝试使用selenium来处理浏览器方面遇到了一些麻烦。 我是这种类型的超级初学者,但我仍在搜索,我发现最相关的响应是我需要以管理员身份运行应用程序,但它没有改变任何东西。这是我的代码和错误消息。非常感谢。
import time
from selenium import webdriver
driver = webdriver.Firefox(executable_path="C:\Program Files\Mozilla Firefox")
我的错误讯息:
Traceback (most recent call last):
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 709, in __init__
restore_signals, start_new_session)
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\subprocess.py", line 997, in _execute_child
startupinfo)
PermissionError: [WinError 5] Access is denied
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Axel\Desktop\PYTHON\code.py", line 3, in <module>
driver = webdriver.Firefox(executable_path="C:\Program Files\Mozilla Firefox")
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 160, in __init__
self.service.start()
File "C:\Users\Axel\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 88, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions.
我很确定这两个错误只是一个,我经历了一大堆线程,但我从来没有正确理解过。我想知道它是否与geckdriver有关(我不知道如何安装。) 非常感谢!
答案 0 :(得分:0)
我相信对于Firefox版本(47.0 +),你需要使用geckodriver。请在此处查看:https://github.com/mozilla/geckodriver/releases
答案 1 :(得分:0)
此错误消息......
selenium.common.exceptions.WebDriverException: Message: 'Mozilla Firefox' executable may have wrong permissions.
...暗示 Mozilla Firefox 可执行文件由于权限错误而无法访问。
使用 Selenium v3.x , GeckoDriver 和 Firefox 时,您必须考虑以下某些事实:
firefox.exe
),您需要通过 GeckoDriver 二进制文件传递绝对路径 参数 executable_path
单引号(即''
)以及原始(r
)开关您的有效代码块如下:
from selenium import webdriver
driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')