python - MAC 上的 Selenium,消息 : 'chromedriver' executable may have wrong permissions

标签 python selenium selenium-webdriver webdriver selenium-chromedriver

我只是想在 Mac 上使用 selenium 做一些非常基本的事情,但我什至无法打开网页。我收到以下错误:

Traceback (most recent call last):
  File "/Users/godsinred/Desktop/InstagramLiker/GmailAccountGenerator.py", line 10, in <module>
    driver = webdriver.Chrome()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 68, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 88, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

下面是我的代码:

from selenium import webdriver
import time

link = "https://accounts.google.com"
driver = webdriver.Chrome()
driver.get(link)
time.sleep(5)

driver.quit()

最佳答案

此处和其他相关帖子中的大多数答案都建议用户将文件移至 /usr/bin如果您只是运行 chromedriver,它们就可以正常工作本地和正常情况下。

但是,如果您使用 cx_freeze 等编译器将 Python 脚本编译为可执行文件,如果您的程序总是使用 chromedriver 的相对链接,您可能无法承受这种奢侈。 .

正如错误消息所示,您编译的程序没有操作 chromedriver 的权限。 。使用到 chromedriver 的相对链接在 Mac 上编译的 Python 程序中,您可以通过编程方式更改 chromedriver 的权限在您的 Python 脚本中使用:

import os
os.chmod('/path/to/chromedriver', 0755) # e.g. os.chmod('/Users/user/Documents/my_project/chromedriver', 0755)
<小时/>

您可以通过执行以下操作来测试:

  1. cd到您的工作目录

  2. $ chmod 755 chromedriver允许您的程序操作它

P.S. 755 is the default numerical permission for files in usr/bin. 664 is the default numerical permission for files in other normal folders (probably your working directory). Thus, when chromedriver complains it does not have the correct permission, you need to grant it a numerical permission equivalent to or greater than 755.

关于python - MAC 上的 Selenium,消息 : 'chromedriver' executable may have wrong permissions,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49787327/

相关文章:

python:如何使用 uwhoisd 代理执行 whois

python - 无法在下拉列表中向下导航,使用 Python 在 Selenium webdriver 中使用 keys.ARROW_DOWN

由于未知协议(protocol) : blob,java.net.URL 类抛出 MalformedException

python - PhantomJS 与 Selenium : Message: 'phantomjs' executable needs to be in PATH

c# - 为 Selenium WebDriver 查找元素

java - Selenium 网络驱动程序 : getText() returning empty String for h2 tag

python - 从测试脚本中运行 pytest 测试用例

python - Ubuntu Python 3 上的 Pygame

python - 如何使用机器学习从扫描文档中提取指定片段

Python Selenium 网络驱动程序 : Debugging