【发布时间】:2020-02-06 19:42:54
【问题描述】:
当我使用“webdriver.Chrome()”时。运行此代码时遇到错误:
from selenium import webdriver
driver = webdriver.Chrome()
出现的错误如下:
Traceback (most recent call last):
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
在处理上述异常的过程中,又发生了一个异常:
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
driver = webdriver.Chrome()
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\User\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 83, in start
os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我不知道该怎么做。而且我还没有找到有同样问题的人。有人知道解决办法吗?
【问题讨论】:
-
PATH是一个环境变量,除其他外,它用于告诉 python 哪些目录(文件夹)可执行文件(例如chromedriver.exe)存在。你得到的错误是抱怨那个python在你的PATH环境变量中找不到chromedriver.exe,所以你要么需要找到一种方法将你计算机上存储chromedriver.exe的目录添加到PATH环境变量中,要么指定完整的调用webdriver.Chrome()时可执行文件的路径。
标签: python python-3.x selenium google-chrome