Skip to content

Instantly share code, notes, and snippets.

@loveklmn
Last active November 24, 2022 05:23
Show Gist options
  • Save loveklmn/d072440e28167b2c48310f9cb66b65b9 to your computer and use it in GitHub Desktop.
Save loveklmn/d072440e28167b2c48310f9cb66b65b9 to your computer and use it in GitHub Desktop.
avoid selenium detect
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", False)
driver = webdriver.Chrome(options=options)
with open('./stealth.min.js') as f: # https://raw.githubusercontent.com/requireCool/stealth.min.js/main/stealth.min.js
js = f.read()
driver.execute_cdp_cmd("Page.addScriptToEvaluateOnNewDocument", {"source": js })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment