可执行路径需要在 Python 中的 PATH 中

Executable path needs to be in PATH in Python

我不断收到此错误:

Traceback (most recent call last):
  File "C:/Users/LENOVO/Desktop/Coding -Winson/PyCharm/opening_webs.py", line 3, in <module>
    driver = webdriver.Chrome('/path/to/chromedriver')
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\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

每次我使用这个代码:

from selenium import webdriver

webdriver.Chrome(executable_path= "Users\LENOVO\AppData\Local\Programs\Python\Python38-32\chromedriver.exe")

试试这个

webdriver.Chrome(executable_path= r"C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\chromedriver.exe")

并确保你有 chrome driver

否则还是会出现这个错误

Traceback (most recent call last): File "C:/Users/LENOVO/Desktop/Coding -Winson/PyCharm/opening_webs.py", line 3, in driver = webdriver.Chrome('/path/to/chromedriver') File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in init self.service.start() File "C:\Users\LENOVO\AppData\Local\Programs\Python\Python38-32\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 可执行文件的副本放入 python 程序所在的当前路径