Successfully resolved BUG: selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs

成功解决BUG:selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH.

Abnormal Interpretation

When using Python to operate selenium, the following error occurs:

selenium.common.exceptions.WebDriverException: Message: ‘chromedriver’ executable needs to be in PATH

The translation of the error into Chinese is:

chromedriver.exeThe file was not found, and the directory corresponding to the file needs to be configured.

The actual encoding error is shown in the image below.

insert image description here

Solutions

This BUG is caused by Selenium being unable to find the executable file of the Chrome driver (chromedriver).

The solution is just to specify the path in the code.

driver = webdriver.Chrome(r'G:\chromedriver_win32\chromedriver.exe')

error recurrence

You can enter the following code in the Python file, and the error shown in the title of this article will appear:

from selenium.webdriver.chrome.options import Options
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By


def get_data(url):
    driver = webdriver.Chrome(r'G:\chromedriver_win32\chromedriver.exe')

    # url = 'https://www.jd.com'
    driver.get(url)

    print(driver.title)


get_data('https://www.jd.com')

other learning materials

Guess you like

Origin blog.csdn.net/hihell/article/details/131690686