【问题标题】:Using Selenium on Raspberry Pi with Chromium在带有 Chromium 的 Raspberry Pi 上使用 Selenium
【发布时间】: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


【解决方案1】:

Ubuntu 将 chromium-chromedriver 构建为 armhf 的 .deb 文件。

因此,您可以在启动板上找到可供下载的chromium-chromedriver armhf builds。只需下载最新版本,由于它们没有依赖项,您可以通过运行dpkg -i chromium-chromedriver_58.0.3029.96-0ubuntu0.14.04.1174_armhf.deb 进行安装。然后 chromedriver 将在/usr/lib/chromium-browser/chromedriver 中可用。

【讨论】:

  • 这对我不起作用。下载geckodriver v0.19.1 tarball 并将geckodriver 移动到/usr/local/bin/ 后,命令geckodriver -b /usr/bin/firefox --webdriver-port 45753 产生错误geckodriver: /lib/arm-linux-gnueabihf/libc.so.6: version 'GLIBC_2.18' not found (required by geckodriver)
  • 我给出了 chromedriver 的说明,而不是 geckodriver。
  • 这对我有用,应该是公认的答案。关键是确保 chromedriver 版本与 pi 上安装的 Chromium 版本匹配。就我而言,我必须更新 Chromium。完成后,只要我在初始化驱动程序时通过/usr/lib/chromium-browser/chromedriver 路径,一切正常。
【解决方案2】:

目前 Chrome 驱动程序不再支持 ARM 处理器架构。

https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=95322

【讨论】:

    猜你喜欢
    • 2017-12-10
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    • 2019-11-14
    • 2018-08-20
    • 2021-04-13
    相关资源
    最近更新 更多