当我使用“ webdriver.Chrome()”时。运行此代码时遇到错误:
from selenium import webdriver
driver = webdriver.Chrome()
这是显示的错误:
Traceback (most recent call last):
File "C:\Users\Olli Lohikoski\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\common\service.py", line 76, in start
stdin=PIPE)
File "C:\Users\Olli Lohikoski\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
restore_signals, start_new_session)
File "C:\Users\Olli Lohikoski\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\Olli Lohikoski\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\Olli Lohikoski\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
我不知道该怎么做。而且我还没有人遇到同样的问题。有人知道解决方法吗?
答案 0 :(得分:0)
您需要chromedriver二进制文件和二进制文件的路径,如下所示:
driver = webdriver.Chrome('/usr/local/bin/chromedriver.exe')
从以下位置按照您的chrome版本下载chromedriver: