【问题标题】:Issues running Selenium with Chromedriver on Raspberry Pi 4在 Raspberry Pi 4 上使用 Chromedriver 运行 Selenium 的问题
【发布时间】:2021-04-13 11:12:42
【问题描述】:

我想知道是否有人可以帮助我解决我遇到的这个错误。

我想使用 Selenium 在使用 Python 的(无头)Raspberry Pi 4 上监控网页。我已经安装了 Selenium 并为 Raspberry PI 安装了 needs to work with AMRHF 的正确版本的 Chromedriver;

这是我正在使用的版本:

chromium-browser:  Chromium 86.0.4240.197
chromedriver: 86.0.4240.197
python 3.7
selenium-3.141.0

这是我的脚本:

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver')

driver.get("https://www.google.com")

driver.close()

这是我得到的 Traceback 错误:

Traceback (most recent call last):
  File "test.py", line 4, in <module>
    driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver')
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/pi/.local/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally.
  (unknown error: DevToolsActivePort file doesn't exist)
  (The process started from chrome location /usr/bin/chromium-browser is no longer running, so ChromeDriver is assuming that Chrome has crashed.)

我花了半天时间尝试不同的东西,但我迷路了。 任何人都可以帮忙吗? 谢谢!

【问题讨论】:

  • 您好,我正在运行 Raspbian GNU/Linux 10 (buster)。我想我使用 PIP 安装了 chromedriver。你认为chromedriver有问题吗?也许我应该重新安装?

标签: python selenium selenium-chromedriver raspberry-pi4


【解决方案1】:

使用apt install 安装chromedriver:

sudo apt install chromium-chromedriver

如果 Chromium 已经安装检查版本,Chromium 和 chromedriver 应该是相同的版本。

使用 pip 安装 Selenium:

pip3 install selenium 

尝试给已经安装的chromedriver权限:

sudo chmod 755 /usr/lib/chromium-browser/chromedriver

Raspberry 与 Ubuntu 20.04 服务器

删除已安装的 Chromium source 并使用 chromedriver 重新安装:

sudo apt purge --remove chromium-browser -y
sudo apt autoremove && sudo apt autoclean -y
sudo apt install chromium-chromedriver

【讨论】:

  • 谢谢。当我尝试授予权限时,它说“不允许操作”。然后我使用了“sudo chmod”,效果很好。我决定用“sudo python3 test.py”而不是通常的“python3 script.py”来运行我的脚本,我得到了; Traceback (most recent call last): File "test.py", line 1, in &lt;module&gt; from selenium import webdriver ModuleNotFoundError: No module named 'selenium'
  • 首先安装sudo apt install chromium-chromedriver chromedriver。然后安装 selenium:pip3 install selenium。这应该工作
  • 嘿,谢谢@sers 回复我。当我运行它们时,它只是说它们都已经安装了。所以不幸的是,我现在遇到了与以前相同的错误。 sudo apt install chromium-chromedriver chromium-chromedriver is already the newest version (86.0.4240.197-rpt1).pip3 install selenium Requirement already satisfied: selenium in /home/pi/.local/lib/python3.7/site-packages (3.141.0) Requirement already satisfied: urllib3 in /usr/lib/python3/dist-packages (from selenium) (1.24.1)
  • 我安装了 Ubuntu 20.04 服务器的 Raspberry,没有问题。您是否单独安装了 Chrome?我安装的版本sudo apt install chromium-chromedriver 是 87.0.4280.88。安装chromium-chromedriver也安装Chromium,不需要单独安装。您的问题可能与驱动程序和 Chromium 版本不兼容有关
  • 感谢您的帮助@sers,但不幸的是,这也不起作用。你是在ubuntu上运行的吗?因为我在 Raspberry Pi 上运行 - 所以也许这就是区别?
猜你喜欢
  • 2022-01-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-21
  • 2023-03-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多