【发布时间】:2017-08-01 15:38:17
【问题描述】:
当我尝试使用 python 脚本在 Ubuntu Linux 14.04 上打开 firefox 浏览器时收到此错误消息:
File "seleniumtest.py", line 3, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
示例代码为:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.google.com')
geckodriver 等依赖已安装。
wget https://github.com/mozilla/geckodriver/releases/download/v0.13.0/geckodriver-v0.13.0-linux64.tar.gz
tar -xvzf geckodriver-v0.13.0-linux64.tar.gz
rm geckodriver-v0.13.0-linux64.tar.gz
chmod +x geckodriver
cp geckodriver /usr/local/bin/
加上"executable_path="/usr/local/bin/geckodriver",输出如下:
File "seleniumtest.py", line 3, in <module>
browser = webdriver.Firefox(executable_path="/usr/local/bin/geckodriver")
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 145, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/service.py", line 74, in start
stdout=self.log_file, stderr=self.log_file)
File "/usr/lib/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1327, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
【问题讨论】:
-
可能重复:stackoverflow.com/questions/38833589/… 和 stackoverflow.com/questions/36141032/… 不同的操作系统,但相同的错误和可能相同的解决方案,即确保您的路径中的任何位置只有一个 geckodriver 实例
-
@Mark Lapierre 是的!我只有一个 geckodriver 实例。我在终端中输入了“which geckodriver”并将链接复制并粘贴到 executable_path="/path/to/geckodriver" 我不认为我有多个 firefox 驱动程序实例。我假设默认预装的 firefox 有自己的驱动程序,而 selenium 包有自己的一组浏览器驱动程序。
-
which -a geckodriver只显示一个吗?即使在指定一个驱动程序后,其他问题之一仍然存在多个驱动程序的问题。 -
@MarkLapierre 是的。它只显示一个。
-
嗯。我知道的唯一另一个问题是,如果您的操作系统不是 64 位,比如驱动程序。是吗?
标签: python selenium firefox ubuntu-14.04