【发布时间】:2021-11-21 22:16:17
【问题描述】:
我刚刚安装并了解了自动化。然后当我想运行这段代码时:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("https://www.google.com")
有这样的错误:
$ C:/Users/HELLO/AppData/Local/Programs/Python/Python39/python.exe d:/Lain-lain/belajarSele.py
Traceback (most recent call last):
File "C:\Users\HELLO\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\HELLO\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\HELLO\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
在处理上述异常的过程中,又发生了一个异常:
Traceback (most recent call last):
File "d:\Lain-lain\belajarSele.py", line 3, in <module>
driver = webdriver.Chrome()
File "C:\Users\HELLO\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\HELLO\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
我该怎么办?
【问题讨论】:
-
嗨。您是否检查过 chrome 驱动程序的正确路径?试试这个
webdriver.Chrome(path where you saved your chrome driver) -
感谢您的回答,这是有效的。
标签: python selenium selenium-webdriver