python - 操作系统错误 : [Errno 8] Exec format error with GeckoDriver and Selenium on MacOS

标签 python selenium firefox selenium-webdriver geckodriver

我正在使用 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/55314269/

相关文章:

python - 使用 Python pypyodbc 到 SQL Server 的连接字符串

python - 如何在 Visual Studio Code 中的当前文件目录中运行 python interactive?

python - 如何在 tkinter 的主窗口前面放置一个顶层窗口?

c# - 在 C# 中使用 selenium webdriver 截取屏幕截图时的空白屏幕截图

python - Selenium:模拟人类打字行为

python - 使用 Python 进行 NVMe 吞吐量测试

java - 尝试使用 Java 和 PhantomJS 从 Selenium 中的网页获取多个链接

python - 检查用户是否已在 python 中使用 selenium 成功登录

css - Customizr slider - 仅限 Firefox 中的奇怪错误

html - 为什么百分比填充/边距不适用于 Firefox 和 Edge 中的 flex 元素?