selenium - chromedriver 可执行文件需要在 PATH 中

新手上路,请多包涵

错误信息:

‘chromedriver’ 可执行文件需要在 PATH 中

我试图在 pycharm 中使用 selenium 编写脚本,但是发生了上述错误。 我已经将我的 selenium 链接到 pycharm,如此处所示(新鲜和最新)

我是 selenium 的新手,不是文件夹“selenium”中的 chromedriver。如果不是,我在哪里可以找到它并将其添加到路径中?

顺便说一句,我尝试在 cmd 中输入“chromedriver”,但是,它没有被识别为内部或外部命令。

错误如下图:

 Traceback (most recent call last):
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 64, in start
    stdout=self.log_file, stderr=self.log_file)
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 947, in __init__
    restore_signals, start_new_session)
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\subprocess.py", line 1224, in _execute_child
    startupinfo)
PermissionError: [WinError 5] Permission denied

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/sebastian/PycharmProjects/web/bot.py", line 10, in <module>
    browser = webdriver.Chrome("C:/Users/sebastian/desktop/selenium-3.0.1")
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 62, in __init__
    self.service.start()
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'selenium-3.0.1' executable may have wrong permissions. Please see https://sites.google.com/a/chromium.org/chromedriver/home

Exception ignored in: <bound method Service.__del__ of <selenium.webdriver.chrome.service.Service object at 0x01EDEAF0>>
Traceback (most recent call last):
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 163, in __del__
    self.stop()
  File "C:\Users\sebastian\AppData\Local\Programs\Python\Python35-32\lib\site-packages\selenium\webdriver\common\service.py", line 135, in stop
    if self.process is None:
AttributeError: 'Service' object has no attribute 'process'

原文由 Sebastian Nielsen 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1.2k
2 个回答

您可以在此处下载 ChromeDriver: https ://sites.google.com/chromium.org/driver/

然后你有多种 选择

  • 将其添加到您的系统 path

  • 把它和你的 python 脚本放在同一个目录下

  • 直接通过 executable_path 指定位置

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

原文由 Maximilian Peters 发布,翻译遵循 CC BY-SA 4.0 许可协议

试试这个 :

 pip install webdriver-manager

 from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())

原文由 BUGATTI AJAY 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题