我正在使用 firefox gecko 驱动程序制作一个机器人,我的机器人不断收到错误消息,我发现消息的来源是:
from selenium import webdriver
browser= webdriver.Firefox()
线条。
我已将错误消息中提到的每个文件添加到路径,包括 gecko 驱动程序、firefox 和其他较小的文档。我完全不知所措
这是错误信息:
Traceback (most recent call last):
File "/usr/local/bin/fuckobot1.py", line 3, in <module>
browser= webdriver.Firefox()
File "/Users/'myname'/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/firefox/webdriver.py", line 164, in __init__
self.service.start()
File "/Users/'myname'/Library/Python/2.7/lib/python/site-packages/selenium/webdriver/common/service.py", line 76, in start
stdin=PIPE)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
最佳答案
这个错误信息...
OSError: [Errno 8] Exec format error
...暗示调用的 GeckoDriver 二进制格式不正确。
您的主要问题是 GeckoDriver 二进制格式相对于底层操作系统的不兼容性。
由于您使用的是 MacOS,因此您需要从 mozilla/geckodriver 下载 geckodriver-v0.23.0-macos.tar.gz , untar/unzip 它并通过参数 executable_path
提供 GeckoDriver 的绝对路径,如下所示:
from selenium import webdriver
browser= webdriver.Firefox(executable_path='/path/to/geckodriver')
关于python - 操作系统错误 : [Errno 8] Exec format error with GeckoDriver and Selenium on MacOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52808760/