当我尝试使用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
which -a geckodriver
只显示一个吗?其中一个问题即使指定了一个驱动程序,仍然存在多个驱动程序的问题。 - Mark Lapierre