P
P
Python Newbie2021-09-13 18:56:15
Google
Python Newbie, 2021-09-13 18:56:15

Google won't let me sign in with selenium python. What to do?

I wrote a code that goes to YouTube and tries to log into a Google account:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.select import Select
import os
import os.path
import sys
from time import sleep
from selenium.webdriver.common.keys import Keys





PATH = os.path.split(os.path.abspath(os.path.realpath(sys.argv[0])))[0] + '/'

options = Options()



#options.add_argument('--headless')

driver = webdriver.Chrome(executable_path=PATH + "chromedriver",
options=options)



try:
    driver.get('https://www.youtube.com/')
    sleep(10)

    
    login = driver.find_element_by_partial_link_text('ВОЙТИ')
    login.click()
    sleep(2)
    email = driver.find_element_by_name('identifier')
    email.clear()
    email.send_keys('test.gmail.com')
    sleep(1)
    email.send_keys(Keys.ENTER)
    
    


    sleep(10)


except Exception as ex:
    print(ex)
finally:
    driver.close()
    driver.quit()


But Google gives this page: KrMxSAvY.jpg?download=1&name=%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%2013-09-2021%2018:20 :44.jpg

Untrusted apps enabled: Ox6Q7KqU.jpg?download=1&name=%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%2013-09-2021%2018:53 :07.jpg

Changing the user-agent didn't help either.

How to login to google account using selenium?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sergey, 2021-09-14
@Levman5

please use the user agent like the browser for example

options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36")

F
Fenix957, 2021-09-13
@Fenix957

Google does not like bots
, use anti-detect browsers, for example, gologin.com
And even with them, everything is not always good

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question