selenium 无法在Linux服务器上使用chromedriver [Exec格式错误]

lkaoscv7  于 2023-02-16  发布在  Linux
关注(0)|答案(1)|浏览(490)

我有一个raspberry-pi运行linux服务器作为平台。因此,没有图形用户界面,我通过终端执行所有的任务,通过SSH-ing进入Pi。平台详细信息:

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

** chrome [此处无问题]**

我已经通过snap安装了Chromium。

  1. chromium --version
  2. >> Chromium 109.0.5414.119 snap

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

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

Chrome驱动程序[问题]

我下载chromedriver这种方式

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

并将Chromedriver解压缩后移动到应用程序文件夹
我得到这个错误时,试图获得chromedriver版本,更不用说运行它

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

我的Python脚本[问题]

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

  1. import selenium
  2. from selenium import webdriver
  3. options = webdriver.ChromeOptions()
  4. options.add_argument("--headless")
  5. options.add_argument("--disable-gpu")
  6. driver = webdriver.Chrome(options=options)
  7. driver.get("https://www.wikipedia.com")
  8. driver.save_screenshot("proof.png")

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

  1. python3 test.py
  2. >> OSError: [Errno 8] Exec format error: 'chromedriver'

∮我已经尝试过的∮

直接通过ChromeDriverManager使用Chrome驱动程序

  1. import selenium
  2. from selenium import webdriver
  3. from webdriver_manager.chrome import ChromeDriverManager
  4. options = webdriver.ChromeOptions()
  5. options.add_argument("--headless")
  6. options.add_argument("--disable-gpu")
  7. driver = webdriver.Chrome(service=Service(ChromeDriverManager(path=".", chrome_type=ChromeType.CHROMIUM).install()), options=options)
  8. driver.get("https://www.wikipedia.com")
  9. driver.save_screenshot("proof.png")

错误

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

检查文件权限

已确保文件具有执行权限

  1. ls -l /usr/local/bin/chromedriver
  2. >> -rwxr-xr-x 1 ubuntu ubuntu 20427216 Sep 8 2021 /usr/local/bin/chromedriver
z6psavjg

z6psavjg1#

由于您有一个以 Chromium 109.0.5414.119 为平台运行linux服务器的raspberry-pi,因此需要使用ChromeDriver

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

您的有效代码行将是:

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

相关问题