当前位置:首页 > 操作系统 > MacOs

python – OSError:[Errno 8]在MacOS上使用GeckoDriver和Selenium执行格式错误

我使用firefox gecko驱动程序制作机器人,我不断收到我的机器人的错误消息,我发现消息的来源是:

<code>from selenium import webdriver

browser= webdriver.Firefox()
</code>

线.

我已将错误消息中提到的每个文件添加到路径,包括gecko驱动程序,firefox和其他较小的文档.我完全失去了

这是错误消息:

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

解决方法:

此错误消息…

<code>OSError: [Errno 8] Exec format error
</code>

…暗示调用的GeckoDriver二进制文件格式不正确.

您的主要问题是GeckoDriver二进制格式与底层操作系统的不兼容性.

当您使用MacOS时,需要从mozilla/geckodriver下载geckodriver-v0.23.0-macos.tar.gz,解压/解压缩它并通过参数executable_path提供GeckoDriver的绝对路径,如下所示:

<code>from selenium import webdriver

browser= webdriver.Firefox(executable_path='/path/to/geckodriver')
</code>

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!

相关教程推荐

其他课程推荐