Skip to content

Instantly share code, notes, and snippets.

@s-bose
Last active May 13, 2022 20:50
Show Gist options
  • Select an option

  • Save s-bose/887f99844c2e6137815fc397063a0175 to your computer and use it in GitHub Desktop.

Select an option

Save s-bose/887f99844c2e6137815fc397063a0175 to your computer and use it in GitHub Desktop.
import os
from dotenv import load_dotenv
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.webdriver import WebDriver
load_dotenv()
CHROMEDRIVER_PATH: str = os.environ.get('CHROMEDRIVER_PATH')
def get_driver(headless: bool = True) -> WebDriver:
options = webdriver.ChromeOptions()
options.add_argument('--disable-gpu')
options.add_argument('--no-sandbox')
options.add_argument('--incognito')
options.add_experimental_option('excludeSwitches', ['enable-logging'])
if headless:
options.add_argument('--headless')
service: Service = Service(CHROMEDRIVER_PATH)
driver: WebDriver = webdriver.Chrome(service=service, options=options)
driver.delete_all_cookies()
return driver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment