我正在使用python和selenium,并从这个网站下载了用于我的windows计算机的chromedriver: http://chromedriver.storage.googleapis.com/index.html?path=2.15/

下载压缩文件后,我将压缩文件解压缩到我的下载文件夹中。然后我把可执行二进制文件(C:\Users\michael\Downloads\chromedriver_win32)的路径放到环境变量“path”中。

然而,当我运行以下代码:

  from selenium import webdriver

  driver = webdriver.Chrome()

... 我一直得到以下错误消息:

WebDriverException: Message: 'chromedriver' executable needs to be available in the path. Please look at     http://docs.seleniumhq.org/download/#thirdPartyDrivers and read up at http://code.google.com/p/selenium/wiki/ChromeDriver

但是-如上所述-可执行文件在路径中(!)…这是怎么回事?


当前回答

可执行路径已弃用!

如果你得到exectuable_path ash been deprecated警告,下面是修复…

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
def test_me(my_name):
    s=Service(ChromeDriverManager().install())    
    chrome_driver = webdriver.Chrome(service=s)
    ...

其他回答

适用于Linux和OSX

步骤1:下载chromedriver

# You can find more recent/older versions at http://chromedriver.storage.googleapis.com/
# Also make sure to pick the right driver, based on your Operating System
wget http://chromedriver.storage.googleapis.com/81.0.4044.69/chromedriver_mac64.zip

对于debian: wget https://chromedriver.storage.googleapis.com/2.41/chromedriver_linux64.zip

步骤2:将chromedriver添加到/usr/local/bin目录

unzip chromedriver_mac64.zip
sudo mv chromedriver /usr/local/bin
sudo chown root:root /usr/local/bin/chromedriver
sudo chmod +x /usr/local/bin/chromedriver

您现在应该可以运行了

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('http://localhost:8000')

没有任何问题

可执行路径已弃用!

如果你得到exectuable_path ash been deprecated警告,下面是修复…

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
def test_me(my_name):
    s=Service(ChromeDriverManager().install())    
    chrome_driver = webdriver.Chrome(service=s)
    ...

在C:\Windows. exe中添加webdriver(chromedriver.exe或geckodriver.exe)。 这对我来说很管用

另一种方法是下载并解压chromedriver,并将'chromedriver.exe'放在C:\Program Files\Python38\Scripts中,然后你不需要提供驱动程序的路径,只需

司机= webdriver.Chrome ()

当你解压缩chromedriver时,请指定一个确切的位置,以便以后可以跟踪它。下面,您将为您的操作系统获得正确的chromedriver,然后将其解压缩到一个确切的位置,这可以在稍后的代码中作为参数提供。

wget http://chromedriver.storage.googleapis.com/2.10/chromedriver_linux64.zip unzip余下