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

2023-12-14

我使用的是 Google Chrome 版本 83.0.4103.116 和 ChromeDriver 83.0.4103.39。我正在尝试在 google colab 中使用 chrome 驱动程序。我在google colab中上传后使用chromedriver的路径。您能指出我在哪里遇到错误吗? 这是代码

import selenium
from selenium import webdriver
wd = webdriver.Chrome(r'/content/chromedriver.exe')

这是错误

---------------------------------------------------------------------------
PermissionError                           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
PermissionError: [Errno 13] Permission denied: '/content/chromedriver.exe'

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)
     86                 raise WebDriverException(
     87                     "'%s' executable may have wrong permissions. %s" % (
---> 88                         os.path.basename(self.path), self.start_error_message)
     89                 )
     90             else:

WebDriverException: Message: 'chromedriver.exe' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

谷歌合作实验室

合作实验室是一个免费的 Jupyter 笔记本环境,无需设置,完全在云中运行,使我们能够编写和执行代码、保存和共享您的分析以及访问强大的计算资源,所有这些都可以通过您的浏览器免费实现。

整个 Colab 运行在云虚拟机中。如果您调查 VM,您会发现当前的 colab 笔记本运行在 Ubuntu 18.04.3 LTS 之上。

所以在使用时Selenium而不是提及网络驱动程序变体以及扩展名,即.exe你需要删除扩展名。因此,您的代码块实际上将是:

import selenium
from selenium import webdriver
wd = webdriver.Chrome('/content/chromedriver')

Update

如果您不确定在哪里Chrome驱动程序下载后,您可以将其移动到已知位置并按如下方式使用它:

!apt-get update
!apt install chromium-chromedriver
!cp /usr/lib/chromium-browser/chromedriver /usr/bin
!pip install selenium

from selenium import webdriver
wd = webdriver.Chrome('/usr/bin/chromedriver')

参考

您可以在以下位置找到一些详细的相关讨论:

  • “Webdrivers”可执行文件可能具有错误的权限。请参阅 https://sites.google.com/a/chromium.org/chromedriver/home
  • MAC 上的 Selenium,消息:“chromedriver”可执行文件可能具有错误的权限
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

WebDriverException:消息:“chromedriver.exe”可执行文件可能通过 Selenium Python 使用 Google Colaboratory 具有错误的权限 的相关文章

随机推荐