Rumah > Artikel > pembangunan bahagian belakang > Mengapa Saya Mendapat \"WebDriverException: \'chromedriver\' Perlu Ada dalam Path\" Apabila Menetapkan Ejen Pengguna dengan Selenium Chromedriver dalam Python?
When attempting to modify your user agent for web scraping using Selenium Chromedriver with Python, you may encounter this error message:
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
This error suggests that the ChromeDriver executable was not found in the locations specified within the PATH variable in your Environment Variables.
To resolve this issue, pass the "executable_path" key with the absolute path of the ChromeDriver along with the ChromeOptions object as an argument while initializing the WebDriver and WebBrowser:
from selenium import webdriver options = webdriver.ChromeOptions() options.add_argument('user-agent = Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.36') driver = webdriver.Chrome(chrome_options=options, executable_path=r'C:\Users\Desktop\chromedriver_win32\chromedriver.exe') driver.get('https://www.google.co.in')
Ensure that you replace the path with the actual location of the ChromeDriver executable on your system. This will locate the ChromeDriver and initialize the browser with the desired user agent, resolving the error message.
Atas ialah kandungan terperinci Mengapa Saya Mendapat \"WebDriverException: \'chromedriver\' Perlu Ada dalam Path\" Apabila Menetapkan Ejen Pengguna dengan Selenium Chromedriver dalam Python?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!