我已经安装了webdriver和selenium。当我试图运行一个代码来打开谷歌时,我会收到这个错误。我已经多次尝试将.exe添加到路径中,但都不起作用。
Message=消息:"chromedriver.exe"可执行文件需要在PATH中。请参阅https://sites.google.com/a/chromium.org/chromedriver/home
现在您可以设置chromedriver进行自动升级:
pip install chromedriver-autoinstaller
代码:
from selenium import webdriver
import chromedriver_autoinstaller
chromedriver_autoinstaller.install() # Check if the current version of chromedriver exists
# and if it doesn't exist, download it automatically,
# then add chromedriver to path
driver = webdriver.Chrome()
driver.get("http://www.python.org")
assert "Python" in driver.title
尝试以下代码进行手动设置:
driver = webdriver.Chrome("full path to chrome driver\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 30)
driver.get("www.google.com")
在执行时安装驱动程序
使用webdriver_manager
python包会将其存储到缓存中,并将确切路径传递给驱动程序
只有存在更新的驱动程序版本时,才会下载
import selenium
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())