python - 'Webdrivers' 可执行文件可能有错误的权限。请参阅 https ://sites. google.com/a/chromium.org/chromedriver/home

标签 python google-chrome selenium selenium-webdriver selenium-chromedriver

我环顾四周检查了这两个文档,但没有找到答案。

我一直在尝试将 InstaPy 用于 python 的 instagram api。在因多个错误而失败并假设 InstaPy 只是遇到一些问题后,我尝试使用 selinium 对其进行原始编码。在插入示例代码并根据自己的喜好对其进行更改后,我只是确保该代码可以正常工作。我收到了一个新错误而不是旧错误,说权限可能不正确。我试过重新安装并以管理员身份运行,但没有任何效果。我该如何解决这个问题和/或这是什么意思

代码:

import time
from selenium import webdriver

driver = webdriver.Chrome('C:\Webdrivers')  # Optional argument, if not specified will search path.
driver.get('http://www.google.com/xhtml');
time.sleep(5) # Let the user actually see something!
search_box = driver.find_element_by_name('q')
search_box.send_keys('ChromeDriver')
search_box.submit()
time.sleep(5) # Let the user actually see something!
driver.quit()

错误:

Traceback (most recent call last):
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 74, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 707, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Python36-32\lib\subprocess.py", line 990, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Access is denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Webdrivers\RawBot.py", line 5, in <module>
    driver = webdriver.Chrome('C:\Webdrivers')  # Optional argument, if not specified will search path.
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Program Files (x86)\Python36-32\lib\site-packages\selenium\webdriver\common\service.py", line 86, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'Webdrivers' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

最佳答案

这个错误信息...

WebDriverException: Message: 'Webdrivers' executable may have wrong permissions.

...暗示您尝试使用的 ChromeDriver 变体具有错误的权限。


你似乎已经尝试过了:

driver = webdriver.Chrome('C:\Webdrivers')  # Optional argument, if not specified will search system $PATH variable.

几句话:

  • 如果您的标的 :

    • 您必须从ChromeDriver Download Location 下载chromedriver_win32.zip并解压缩以供使用。
    • 此外,如果您明确指定 Chromedriver 二进制路径,您还必须附加二进制扩展名,即 chromedriver.exe
    • 在提及 Chromedriver 二进制路径时,您必须使用单个 forward slash(/) 以及原始 (r) 开关,否则您必须使用转义的 backslash(\\)
    • 因此您的有效代码行将是:

      driver = webdriver.Chrome(executable_path=r'C:/path/to/chromedriver.exe')
      
  • 如果您的标的 :

    • 您必须从ChromeDriver Download Location 下载chromedriver_linux64并解压以供使用。
    • 此外,如果您明确指定 Chromedriver 二进制路径,您不必为可执行二进制文件提供任何扩展名,即 chromedriver.
    • 在提及 Chromedriver 二进制路径时,您必须使用单个 forward slash(/)
    • 因此您的有效代码行将是:

      driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
      
  • 如果您的标的 :

    • 您必须从ChromeDriver Download Location 下载chromedriver_mac64并解压以供使用。
    • 此外,如果您明确指定 Chromedriver 二进制路径,您不必为可执行二进制文件提供任何扩展名,即 chromedriver.
    • 在提及 chromedriver 二进制路径时,您必须使用单个 forward slash(/)
    • 因此您的有效代码行将是:

      driver = webdriver.Chrome(executable_path='/path/to/chromedriver')
      

关于python - 'Webdrivers' 可执行文件可能有错误的权限。请参阅 https ://sites. google.com/a/chromium.org/chromedriver/home,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47148872/

相关文章:

python - Selenium - set_window_size() 始终返回相同大小的窗口,与指定的尺寸无关

python - 如何让脚本等待一段时间,以便加载来自 ajax 响应的数据,然后捕获网页

python - Tweepy 使用用户名/密码进行身份验证

python - 使用 Spark 对分组数据进行快速行间计算

javascript - 如何使用扩展程序在 Google Chrome 中加载页面?

javascript - 如何在 Chrome 中将 DOM 存储为 HTML 文件?

css - Chrome 中 MIME 类型错误的字体

selenium - 使用 css 选择器 python 选择一个元素

python - 如何使用 BeautifulSoup 4 替换或删除 HTML 实体,如 "&nbsp;"

python - 在一行中向数组添加值