【问题标题】:WebDriverException: Message: 'chromedriver.exe' executable may have wrong permissions using Google Colaboratory through Selenium PythonWebDriverException:消息:“chromedriver.exe”可执行文件可能通过 Selenium Python 使用 Google Colaboratory 具有错误权限
【发布时间】:2020-10-22 22:46:11
【问题描述】:

我使用的是 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

【问题讨论】:

    标签: python selenium google-chrome selenium-chromedriver google-colaboratory


    【解决方案1】:

    谷歌实验室

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

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

    因此,在使用Selenium 而不是提及WebDriver 变体以及扩展名(即.exe)时,您需要删除扩展名。因此,您的代码块将是:

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

    更新

    如果您不确定 ChromeDriver 的下载位置,您可以将其移动到已知位置并按如下方式使用:

    !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')
    

    参考文献

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

    【讨论】:

    • 在尝试不使用 exe 运行时,会出现此错误 WebDriverException: Message: 'chromedriver' executable needs to be in PATH.请看sites.google.com/a/chromium.org/chromedriver/home
    • '/content/chromedriver.exe'是我在google colab中上传chromedrive文件后得到的路径
    • @SoudipKarmakar 这听起来完全是一个不同的问题。请问您能根据您的新要求提出一个新问题吗?
    • wd = webdriver.Chrome(r'/content/chromedriver.exe' ) 我在说什么。在google colab中上传chromedriver文件后,'/content/chromedriver.exe'是上传文件的路径。路径没有错误。但是,当我使用 this-wd=webdriver.Chrome('/content/chromedriver') 时,我得到了这个错误——当试图在没有 exe 的情况下运行时,它给出了这个错误 WebDriverException:消息:'chromedriver' 可执行文件需要在 PATH 中。请参阅 sites.google.com/a/chromium.org/chromedriver/home
    • @SoudipKarmakar 查看更新后的答案并告诉我状态。
    【解决方案2】:

    我创建了一个库来帮助在 Colab 中更轻松地使用 selenium。

    你可以这样称呼

    !pip install kora -q
    from kora.selenium import wd
    wd.get(url)
    

    【讨论】:

    • 从 kora.selenium import wd 执行此操作后,我收到此错误。WebDriverException:消息:服务 chromedriver 意外退出。状态码是:-6
    • 尝试在新笔记本中启动它。它可能会干扰我们之前的 chromedriver。
    • 我从新笔记本开始。 wd.get('google.com') 在这行之后我得到这个错误:MaxRetryError: HTTPConnectionPool(host='127.0.0.1', port=44451): Max retries exceeded with url: /session/d653bd20a28ef757c930aba4d7283777/url (由 NewConnectionError 引起(': 无法建立新连接: [Errno 111] Connection denied',))
    • 我觉得还可以。由于其他一些功能,它可能会发生。
    • stackoverflow.com/questions/62703937/… 能否请您检查一下问题。我在那里发布了整个代码以及我得到的错误。
    猜你喜欢
    • 1970-01-01
    • 2022-01-20
    • 2018-03-22
    • 1970-01-01
    • 2019-04-17
    • 2018-09-22
    • 1970-01-01
    • 2022-01-19
    • 2020-12-06
    相关资源
    最近更新 更多