Python selenium using cookies

Viewed 1215

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?

2 Answers

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

You can import your default Chrome browser profile to be used by Selenium ChromeDriver as following:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\yourUserFolderName\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', chrome_options=options)
Related