python - 无法使用 Selenium 在 Pycharm 中运行基本 Py 程序

标签 python selenium pycharm

我对编码很陌生。尝试运行过去 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

提前致谢。

最佳答案

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

关于python - 无法使用 Selenium 在 Pycharm 中运行基本 Py 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59435904/

相关文章:

python - 如何创建一个数据框,其中日期范围作为列中的值?

java - 打开pycharm时找不到jdk?

python - 如何禁用错误消息 'print keyword can' t 用作 pycharm 中的 python 2' 中的标识符?

python - 如何在同一选项卡中使用 selenium 函数? (在 python 上)

python - 使用 PyCharm 在 Docker 中使用 Django

python - Beautifulsoup 返回奇怪的字符(中文)

python - 我如何使用 Keras 获得可重现的结果?

用于列表清理的Java one liner

java - 获取 DIV 值、CSS 值 - WebDriver (Selenium 2) - JAVA

selenium - 在 Docker 容器中执行 Firefox 浏览器进行 Selenium 测试