【发布时间】:2020-04-03 23:36:28
【问题描述】:
我一直在为我的 python 项目使用 Google Colab。我想使用 Google Colab 学习和实现 Selenium。我正在尝试登录 Facebook,如下所示。但是,我被“权限错误”困住了。我查看了各种帖子并尝试执行建议的解决方案,例如 (Selenium on MAC, Message: 'chromedriver' executable may have wrong permissions),但 没有帮助。
我尝试过的。
- 建议参考https://sites.google.com/a/chromium.org/chromedriver/home 文章
- 使用 chmod 755 允许可执行权限
- 在 Colab 环境的不同文件夹中引用了“chromedriver.exe”,但没有成功
代码:
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
user_name = 'Username'
password = 'Password'
os.chmod('/content/chromedriver.exe', 755)
driver = webdriver.Chrome(executable_path='/content/')
driver.get("https://www.facebook.com")
element = driver.find_element_by_id("email")
element.send_keys(user_name)
element = driver.find_element_by_id("pass")
element.send_keys(password)
element.send_keys(Keys.RETURN)
driver.close()
完全错误:
---------------------------------------------------------------------------
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/'
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: '' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我的 Colab 环境快照
有人可以帮我解决这个问题吗?
PS: 相同的代码使用 Jupyter Notebook、Eclipse IDE 工作。但从长远来看,我想摆脱对 Jupyter Notebooks 的依赖并依赖基于云的 Notebook 环境,例如 Google Colab,理论上这应该让我专注于代码而不是解决库/兼容性/权限/等问题。
【问题讨论】:
-
你用
-r递归chmod了吗?
标签: python selenium google-chrome selenium-chromedriver google-colaboratory