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/52808760/

相关文章:

python - 排列,但有一些数字按顺序排列

javascript - 如何将大量文本发送到可编辑的 ="true"元素中?

selenium - 使用 Gatling 进行功能测试

Python:Selenium 无法在 UDOO 上找到空闲端口

javascript - Firefox 在 iframe 中打印 PDF 会引发错误

python - 如何使用 conn.send() 向客户端发送数据

python - 如何将 Bokeh 网格图保存为单个文件

python - Python 请求中的 PDF

java - testng 测试通过 selenium 网格返回 ie 驱动程序路径错误,但测试适用于 Firefox

javascript - 有没有办法通过 Firebug 中的快捷方式运行 JavaScript 代码?