Skip to content

Instantly share code, notes, and snippets.

@aahnik
Last active November 11, 2020 17:57
Show Gist options
  • Save aahnik/7220eac2b1463d6449eff7294bd25349 to your computer and use it in GitHub Desktop.
Save aahnik/7220eac2b1463d6449eff7294bd25349 to your computer and use it in GitHub Desktop.
Using user data dir in selenium. Using a session. Reuse saved cookies. sample_code_selenium_using_user_data_dir.py
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
session_path = 'path/of/folder/'
chrome_driver_path = 'path/of/chrome-driver-executable'
url = 'url'
chrome_options = Options()
chrome_options.add_argument(f'--user-data-dir={session_path}')
driver = webdriver.Chrome(options=chrome_options,
executable_path=chrome_driver_path)
driver.get(url)
# manually sign in into google for first time
# from the next time use same session_path
@aahnik
Copy link
Author

aahnik commented Nov 11, 2020

@aahnik
Copy link
Author

aahnik commented Nov 11, 2020

Dark mode

code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment