我有一个raspberry-pi运行linux服务器作为平台。因此,没有图形用户界面,我通过终端执行所有的任务,通过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
** chrome [此处无问题]**
我已经通过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
Chrome驱动程序[问题]
我下载chromedriver这种方式
wget https://chromedriver.storage.googleapis.com/2.37/chromedriver_linux64.zip
并将Chromedriver解压缩后移动到应用程序文件夹
我得到这个错误时,试图获得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使用Chrome驱动程序
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
1条答案
按热度按时间z6psavjg1#
由于您有一个以 Chromium 109.0.5414.119 为平台运行linux服务器的raspberry-pi,因此需要使用ChromeDriver:
chromedriver_linux64.tar.gz
*您的有效代码行将是: