Selenium + Google Colab错误:“ chromedriver”可执行文件必须位于PATH中

克里斯托弗·蔡

我在此线程中使用@ korakot-chaovavanich提供的代码。如何在协作Google上使用Selenium?我确实需要一个解决方案以使其在Google Colab上正常工作。

# install chromium, its driver, and selenium
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# open it, go to a website, and get results
wd = webdriver.Chrome('chromedriver',options=options)
wd.get("https://www.google.com")
print(wd.page_source)  # results

我已经在Google Colab中进行了测试,但是我不知道为什么它无法正常工作。我试图查看/ usr / lib下的内容,但是找不到任何“ chromium-browser”文件夹。我不知道chromedriver在Google Colab中的安装位置。

在Google Colab中执行此代码所产生的错误消息:

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following package was automatically installed and is no longer required:
  libnvidia-common-410
Use 'apt autoremove' to remove it.
The following additional packages will be installed:
  chromium-browser chromium-browser-l10n chromium-codecs-ffmpeg-extra
Suggested packages:
  webaccounts-chromium-extension unity-chromium-extension adobe-flashplugin
The following NEW packages will be installed:
  chromium-browser chromium-browser-l10n chromium-chromedriver
  chromium-codecs-ffmpeg-extra
0 upgraded, 4 newly installed, 0 to remove and 16 not upgraded.
Need to get 68.5 MB of archives.
After this operation, 251 MB of additional disk space will be used.
Ign:1 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-codecs-ffmpeg-extra amd64 74.0.3729.169-0ubuntu0.18.04.1
Ign:2 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-browser amd64 74.0.3729.169-0ubuntu0.18.04.1
Ign:3 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-browser-l10n all 74.0.3729.169-0ubuntu0.18.04.1
Ign:4 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-chromedriver amd64 74.0.3729.169-0ubuntu0.18.04.1
Err:1 http://security.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-codecs-ffmpeg-extra amd64 74.0.3729.169-0ubuntu0.18.04.1
  404  Not Found [IP: 91.189.88.31 80]
Err:2 http://security.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-browser amd64 74.0.3729.169-0ubuntu0.18.04.1
  404  Not Found [IP: 91.189.88.31 80]
Err:3 http://security.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-browser-l10n all 74.0.3729.169-0ubuntu0.18.04.1
  404  Not Found [IP: 91.189.88.31 80]
Err:4 http://security.ubuntu.com/ubuntu bionic-updates/universe amd64 chromium-chromedriver amd64 74.0.3729.169-0ubuntu0.18.04.1
  404  Not Found [IP: 91.189.88.31 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/chromium-codecs-ffmpeg-extra_74.0.3729.169-0ubuntu0.18.04.1_amd64.deb  404  Not Found [IP: 91.189.88.31 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/chromium-browser_74.0.3729.169-0ubuntu0.18.04.1_amd64.deb  404  Not Found [IP: 91.189.88.31 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/chromium-browser-l10n_74.0.3729.169-0ubuntu0.18.04.1_all.deb  404  Not Found [IP: 91.189.88.31 80]
E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/universe/c/chromium-browser/chromium-chromedriver_74.0.3729.169-0ubuntu0.18.04.1_amd64.deb  404  Not Found [IP: 91.189.88.31 80]
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
cp: cannot stat '/usr/lib/chromium-browser/chromedriver': No such file or directory
Requirement already satisfied: selenium in /usr/local/lib/python3.6/dist-packages (3.141.0)
Requirement already satisfied: urllib3 in /usr/local/lib/python3.6/dist-packages (from selenium) (1.24.3)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
     75                                             stderr=self.log_file,
---> 76                                             stdin=PIPE)
     77         except TypeError:

4 frames
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver': 'chromedriver'

During handling of the above exception, another exception occurred:

WebDriverException                        Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/selenium/webdriver/common/service.py in start(self)
     81                 raise WebDriverException(
     82                     "'%s' executable needs to be in PATH. %s" % (
---> 83                         os.path.basename(self.path), self.start_error_message)
     84                 )
     85             elif err.errno == errno.EACCES:

WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
锡莱

问题来自Google Chrome和Chromium Browser之间的版本不匹配,导致命令apt install chromium-chromedriver失败。这可能是由于Selenium的更新。您需要使用命令更新每个软件包apt-get update,以避免工具的版本不匹配。在colab上尝试以下操作:

# install chromium, its driver, and selenium
!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium
# set options to be headless, ..
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
# open it, go to a website, and get results
wd = webdriver.Chrome('chromedriver',options=options)
wd.get("https://www.website.com")
print(wd.page_source)  # results

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

在Selenium / Python中出现错误-chromedriver可执行文件必须位于PATH中

带有Selenium错误的PhantomJS:消息:“ phantomjs”可执行文件必须位于PATH中

Python Selenium错误:“ WebDriverException:'login'可执行文件必须位于PATH中。”

Mac上的Python +浏览器:错误-“ chromedriver”可执行文件必须位于PATH中

Mac上的Python中的Selenium-Geckodriver可执行文件必须位于PATH中

使用Python的Selenium-Geckodriver可执行文件必须位于PATH中

WebDriverException:消息:通过Selenium Chromedriver python设置UserAgent时,“ chromedriver”可执行文件需要位于PATH中

WebDriverException:消息:“ chromedriver.exe”可执行文件可能通过Selenium Python使用Google合作实验室具有错误的权限

OSX修复Selenium Chromedriver启动错误生成未知系统错误-86可执行文件中的CPU类型错误?

selenium.common.exceptions.WebDriverException:消息:“ Headless Chrome浏览器”可执行文件在PATH错误中

Selenium Firefox webdriver 通过 geckodriver 导致错误:“geckodriver”可执行文件需要在 PATH 中

错误消息:“'chromedriver'可执行文件必须在路径中可用”

selenium.common.exceptions.WebDriverException:消息:“库”可执行文件可能对ChromeDriver具有错误的权限

必须使用GeckoDriver和Firefox通过Selenium将'geckodriver'可执行文件放在PATH中

在Selenium中,ChromeDriver可执行文件如何找到Chrome浏览器?

为 Windows 安装 Chromedriver - selenium.common.exceptions.WebDriverException:消息:'chromedriver.exe' 可执行文件需要在 PATH 中

“ Webdrivers”可执行文件可能具有错误的权限。请参阅https://sites.google.com/a/chromium.org/chromedriver/home

Google Colab文件下载未能获取错误

Google Colab Notebook错误-找不到文件

selenium.common.exceptions.WebDriverException:消息:“ firefox”可执行文件必须与GeckoDriver Firefox Selenium和Python一起放在PATH中

即使通过Selenium和Python使用ChromeDriverManager之后,为什么PATH中的“ chromedriver”可执行文件也不可用

Selenium with Python-消息:“ operadriver”可执行文件需要放在PATH中

Selenium 和 python:“消息:'geckodriver' 可执行文件需要在 PATH 中。”

“ chromedriver”可执行文件必须位于PATH中,但已经存在

Firefox 50出现Selenium 3.0.2错误:可执行文件可能具有错误的权限

使用chromedriver和Selenium创建Python可执行文件

系统错误:exec:“部署”:在$ PATH中找不到可执行文件

Windows上的kubectl diff返回错误:在PATH中找不到可执行文件

在 $PATH 中找不到可执行文件:未知错误消息