I saw following posts.
Selenium Google Login Block Selenium Google Login Block Problem to login Gmail account with Selenium Python Problem to login Gmail account with Selenium Python
My goal is to login google through google colab.
I used code below
options = webdriver.ChromeOptions()
options.add_argument("--headless")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_experimental_option("useAutomationExtension", False)
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_argument('--disable-dev-shm-usage')
options.add_argument("--no-sandbox")
driver = webdriver.Chrome(
options=options
)
driver.execute_script("Object.defineProperty(navigator, 'webdriver', {get: () => undefined})")
# Initializing a list with two Useragents
useragentarray = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.58 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.58 Safari/537.36",
]
for i in range(len(useragentarray)):
# Setting user agent iteratively as Chrome 108 and 107
driver.execute_cdp_cmd("Network.setUserAgentOverride", {"userAgent": useragentarray[i]})
print(driver.execute_script("return navigator.userAgent;"))
driver.get("https://www.httpbin.org/headers")
Then, I got follow headers.
{
"headers": {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip, deflate, br",
"Host": "www.httpbin.org",
"Sec-Fetch-Dest": "document",
"Sec-Fetch-Mode": "navigate",
"Sec-Fetch-Site": "none",
"Sec-Fetch-User": "?1",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.6312.58 Safari/537.36",
"X-Amzn-Trace-Id": "Root=1-65fe5243-35dffc7e6b07d54d014091e4"
}
}
Then, tried to login. But google detected as bot.
What should I do?