WebDriverException: Message: 'chromedriver' executable needs to be in PATH while setting UserAgent through Selenium Chromedriver python

前端 未结 1 1454
栀梦
栀梦 2020-11-22 12:39

I\'m a newbie in webscraping, I\'m trying to modify my user agent using these lines :

from selenium import webdriver
chrome_path = r\'C:\\Users\\Desktop\\chr         


        
相关标签:
1条回答
  • 2020-11-22 13:00

    This error message...

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

    ...implies that the ChromeDriver was not found within the locations specified within PATH variable within Environment Variables.

    Solution

    You need to pass the Key executable_path along with the Value referring to the absolute path of the ChromeDriver along with the ChromeOptions object as an argument while initializing the WebDriver and WebBrowser as follows :

    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')
    
    0 讨论(0)
提交回复
热议问题