You need to make sure that the chromedriver
executable is available in your PATH
. Otherwise, Selenium will throw this error:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://chromedriver.chromium.org/home
The best way to fix this error is to use the webdriver-manager
package. It will make sure that you have a valid chromedriver
executable in PATH
and if it is not available, it will download it automatically. You can install it using PIP:
$ pip install webdriver-manager
And use it in your Python code like this:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
# Open Scrapingbee's website
driver.get("http://www.scrapingbee.com")
The code might take a second or two on the initial run as it has to download the chromedriver
binary. Successive runs should be a lot faster.