Last active
May 13, 2022 20:50
-
-
Save s-bose/887f99844c2e6137815fc397063a0175 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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