gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 07:03:45 29 4
gpt4 key购买 nike

我只是想在 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/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com