Search code examples
pythonseleniumgoogle-chromeselenium-chromedriverdriver

Python selenium using cookies


Hello i have question for chromedriver. I want my own histories, cookies and all other things from my original chrome browser. if this is not possible how to use original chrome browser instead of driver?


Solution

  • you can use chrome profile (see below image to figure out which profile you want to launch)

    1. Default Profile :

    Code :

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument("user-data-dir=C:\\Users\\***\\AppData\\Local\\Google\\Chrome\\User Data")
    driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', options=options)
    driver.get("https://www.google.co.in")
    
    1. for customized profiles :

    Code :

    from selenium import webdriver
    
    options = webdriver.ChromeOptions()
    options.add_argument("user-data-dir=C:\\Users\\***\\AppData\\Local\\Google\\Chrome\\User Data")
    driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', options=options)
    driver.get("https://www.google.co.in")
    

    You can get profile while running chrome://version/ in Google chrome.

    enter image description here