树莓派Linux服务器无法使用Chromedriver:Exec格式错误
问题描述
环境信息
树莓派运行Ubuntu服务器,架构信息如下:
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
设备无图形界面,所有操作通过SSH执行。
Chromium(正常运行)
已通过snap安装Chromium,版本:
chromium --version >> Chromium 109.0.5414.119 snap
可正常以无头模式运行并截图:
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 --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' - 检查文件权限,确认Chromedriver具备执行权限:
ls -l /usr/local/bin/chromedriver >> -rwxr-xr-x 1 ubuntu ubuntu 20427216 Sep 8 2021 /usr/local/bin/chromedriver
需求
目前问题仍未解决,寻求可行解决方案。
内容的提问来源于stack exchange,提问作者Aakash Dusane
相关产品推荐
相关产品推荐

