【问题标题】:Unable to use chromedriver on linux server [Exec format error]无法在 Linux 服务器上使用 chromedriver [Exec 格式错误]
【发布时间】:2023-02-16 03:06:46
【问题描述】:

我有一个运行 linux-server 作为平台的树莓派。因此没有 GUI,我通过 SSH-ing 进入 Pi 通过终端执行我的所有任务。平台详情:

uname -a

>> Linux ubuntu 5.4.0-1080-raspi #91-Ubuntu SMP PREEMPT Thu Jan 19 09:35:03 UTC 2023 aarch64 aarch64 aarch64 GNU/Linux

Chromium [这里没有问题]

我已经通过 snap 安装了 Chromium。

chromium --version
>> Chromium 109.0.5414.119 snap

我能够运行 Chromium、导航到网站并拍摄快照

chromium --headless --disable-gpu --screenshot https://www.wikipedia.com

>> 0215/140750.965255:WARNING:bluez_dbus_manager.cc(247)] Floss manager not present, cannot set Floss enable/disable.
[0215/140752.998408:WARNING:sandbox_linux.cc(385)] InitializeSandbox() called with multiple threads in process gpu-process.
[0215/140802.665622:INFO:headless_shell.cc(223)] 84646 bytes written to file screenshot.png

Chromedriver [问题]

我用这种方式下载了chromedriver

wget https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip

并在解压后将 Chromedriver 移动到 applications 文件夹

尝试获取 chromedriver 版本时出现此错误,更不用说运行它了

chromedriver --version
>> bash: /usr/local/bin/chromedriver: cannot execute binary file: Exec format error

我的 Python 脚本 [问题]

这是我希望最终能够运行的脚本

import selenium
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--disable-gpu")
driver = webdriver.Chrome(options=options)
driver.get("https://www.wikipedia.com")
driver.save_screenshot("proof.png")

这是我尝试运行它时遇到的错误

python3 test.py

>> OSError: [Errno 8] Exec format error: 'chromedriver'

我已经尝试过的

通过 ChromeDriverManager 直接使用 chromedriver

import selenium
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--disable-gpu")
driver = webdriver.Chrome(service=Service(ChromeDriverManager(path=".", chrome_type=ChromeType.CHROMIUM).install()), options=options)
driver.get("https://www.wikipedia.com")
driver.save_screenshot("proof.png")

错误

OSError: [Errno 8] Exec format error: './.wdm/drivers/chromedriver/linux64/109.0.5414/chromedriver'

检查文件权限

确保文件具有执行权限

ls -l /usr/local/bin/chromedriver

>> -rwxr-xr-x 1 ubuntu ubuntu 20427216 Sep  8  2021 /usr/local/bin/chromedriver

【问题讨论】:

  • 您的 chromedriver 可能是为 x86_64 架构编译的。你试过sudo apt-get install chromium-chromedriver吗?

标签: python linux selenium-webdriver raspberry-pi selenium-chromedriver


【解决方案1】:

当你有一个 raspberry-pi 运行 linux-server 作为平台时铬 109.0.5414.119你需要使用 ChromeDriver 的:

  • Version 109.0
  • Linux 兼容格式,即chromedriver_linux64.tar.gz

您的有效代码行将是:

wget https://chromedriver.storage.googleapis.com/109.0.5414.74/chromedriver_linux64.tar.gz

【讨论】:

    猜你喜欢
    • 2016-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-24
    • 2018-05-15
    • 2022-01-22
    相关资源
    最近更新 更多