繁体   English   中英

权限错误 [winerror 5] 访问被拒绝-Selenium chrome webdriver

[英]Permission error [winerror 5] access is denied-Selenium chrome webdriver

我正在学习有关使用 selenium 的教程,但在开始时遇到了问题。 也就是说,当我尝试运行下面的代码时,出现以下错误。 我见过其他用户遇到同样的问题,我尝试了他们的解决方案,但没有奏效。

这些解决方案包括:

  • 以管理员身份运行 pycharm,
  • 为所有人设置权限
  • subprocess.py 和 service.py 的组/用户名
  • 站点包(以及几乎其中的每个文件/文件夹)以完全访问。
from selenium import webdriver
driver = webdriver.Chrome(r"C:\Users\User\AppData\Local\Programs\Python\Python37-32\Lib\site-packages\selenium\webdriver\chrome")
driver.get("http://python.org")

这是完整的错误消息:

回溯(最近一次调用):文件“C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\selenium\\webdriver\\common\\service.py”,第 76 行,在start stdin=PIPE) 文件“C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\subprocess.py”,第 775 行,在init restore_signals, start_new_session) 文件“C:\\Users\\User \\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\subprocess.py", line 1178, in _execute_child startupinfo) PermissionError: [WinError 5] Access is denied

在处理上述异常的过程中,又发生了一个异常:

回溯(最近一次调用):文件“C:/Users/User/PycharmProjects/PythonProject/DataCollection”,第 2 行,在 driver = webdriver.Chrome(r"C:\\Users\\User\\AppData\\Local\\Programs\\Python \\Python37-32\\Lib\\site-packages\\selenium\\webdriver\\chrome") 文件 "C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\selenium\\webdriver\\chrome \\webdriver.py”,第 73 行,在init self.service.start() 文件“C:\\Users\\User\\AppData\\Local\\Programs\\Python\\Python37-32\\lib\\site-packages\\selenium\\webdriver\\common \\service.py”,第 88 行,在 start os.path.basename(self.path), self.start_error_message) selenium.common.exceptions.WebDriverException: 消息:'chrome' 可执行文件可能有错误的权限。 请参阅https://sites.google.com/a/chromium.org/chromedriver/home

首先,用/替换所有\\

然后在文件位置添加可执行文件名:

driver = webdriver.Chrome(r'C:/Users/User/AppData/Local/Programs/Python/Python37-32/Lib/site-packages/selenium/webdriver/chrome/chromedriver.exe')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM