【问题标题】:unable to run basic Py program in Pycharm with Selenium无法使用 Selenium 在 Pycharm 中运行基本的 Py 程序
【发布时间】:2020-04-13 14:18:38
【问题描述】:

我对编码很陌生。尝试从过去 20 天运行以下基本行,并收到以下错误。请帮忙。尝试安装卸载 python、selenium 和 pycharm。还是一样的问题:(

我的代码:

from selenium import webdriver
browser = webdriver.Chrome(executable_path = 'C:\Program Files (x86)\Google\Chrome\Application')
browser.get('https://www.google.com')
browser.quit()

错误 -

"C:\Python 3.7.6\python.exe" C:/Users/PycharmProjects/sel/sel1.py
Traceback (most recent call last):
  File "C:\Python 3.7.6\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Python 3.7.6\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\Python 3.7.6\lib\subprocess.py", line 1207, 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:/Users/PycharmProjects/sel/sel1.py", line 2, in <module>
    browser = webdriver.Chrome(executable_path = 'C:\Program Files (x86)\Google\Chrome\Application')
  File "C:\Python 3.7.6\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Python 3.7.6\lib\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: 'Application' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home


Process finished with exit code 1

提前致谢。

【问题讨论】:

  • 所以我需要下载chromedriver,然后在exec路径中提供路径,对吗??
  • 反斜杠是 Python 中的转义字符。所以你的路径不是你所期望的。在路径中使用双反斜杠或正斜杠。

标签: python selenium pycharm


【解决方案1】:

您的可执行路径存在严重问题。抛出的错误表明您的程序对 chrome 驱动程序的访问被阻止。将 chrome 驱动程序的位置更改为其他位置(桌面、用户目录等),并将代码中的可执行路径更改为放置 chromedriver 的新路径,您应该没问题

【讨论】:

  • 我希望你已经下载了 chromedriver 并且你没有尝试在普通的 chrome 浏览器中使用 selenium
  • 正确的先生,我使用的是普通的 Chrome 浏览器路径。所以我知道我需要下载 chromedriver 然后在 exec 路径中提供该路径对吗??
  • 可执行路径是chrome驱动的路径。所以是的,是的
猜你喜欢
  • 2015-11-22
  • 2020-11-18
  • 2018-12-23
  • 2016-09-23
  • 2017-07-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多