【发布时间】:2015-07-02 16:39:34
【问题描述】:
所以我尝试使用 Chromium 在我的树莓派上运行 Selenium,但由于某种原因,我无法编译我的 python 文件。我不断收到以下错误:
Traceback (most recent call last):
File "test.py", line 4, in <module>
driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver.exe'))
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 75, in start
os.path.basename(self.path), docs_msg)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
这是我要运行的 python 代码:
from selenium import webdriver
import os
driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver'))
driver.get("http://www.google.com")
driver.quit()
有什么想法吗?
更新
删除chromedriver末尾的'.exe'后,现在会产生以下错误:
Traceback (most recent call last):
File "test.py", line 4, in <module>
driver = webdriver.Chrome(os.path.expanduser('/usr/bin/chromedriver'))
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
self.service.start()
File "/usr/local/lib/python2.7/dist-packages/selenium-2.46.0-py2.7.egg/selenium/webdriver/chrome/service.py", line 68, in start
self.service_args, env=env, stdout=PIPE, stderr=PIPE)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 8] Exec format error
【问题讨论】:
-
你需要为它提供一个
chromedriver二进制for linux,而不是chromedriver.exe。 -
我去掉了 chromedriver 文件末尾的“.exe”。话虽如此,我可以向你保证,我使用的是专门为 linux 制作的二进制文件。
-
从文件名的末尾删除
.exe不会减少Windows 的可执行性。按照我提供的链接,下载适用于 linux 的链接并使用。 -
就像我在之前的评论中提到的那样。我已经下载了 chromedriver for linux。我一直在使用它。我在文件末尾有“.exe”的唯一原因是因为我认为应该完整地写出整个文件名。很抱歉造成混乱。
-
从命令行,在 PI 上,尝试运行
/usr/bin/chromedriver。你得到了什么?
标签: python selenium chromium selenium-chromedriver