简体   繁体   English

如何使用 selenium python 登录谷歌帐户

[英]how to log in to the google account using selenium python

I've been trying to log into my google account using selenium but once I pass in the email and hit enter it redirects to the following message我一直在尝试使用 selenium 登录我的谷歌帐户,但是一旦我传入 email 并按回车键,它就会重定向到以下消息

"This browser or app may not be secure. Learn more Try using a different browser. If you're already using a supported browser, you can refresh your screen and try again to sign in." “此浏览器或应用程序可能不安全。了解更多尝试使用其他浏览器。如果您已经在使用受支持的浏览器,则可以刷新屏幕并再次尝试登录。”

Here is my python code:这是我的 python 代码:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
options = webdriver.ChromeOptions()
options.add_argument("--enable-javascript")
driver = webdriver.Chrome(executable_path='path/to/chrome/driver',chrome_options = options)
url = "https://accounts.google.com/signin"

driver.get(url)
username = 'email'
password = 'password'

email_phone = driver.find_element_by_id('identifierId')
email_phone.send_keys(username)
email_phone.send_keys(Keys.RETURN)
email_phone = driver.find_element_by_id('password')
email_phone.send_keys(password)
email_phone.send_keys(Keys.RETURN)

please note that I'm new to python and selenium.请注意,我是 python 和 selenium 的新手。 I would very much appreciate your help.非常感谢您的帮助。 Thank you in advance先感谢您

I have tried to use the methods described in Selenium Google Login Block but it still gave me the same message我尝试使用Selenium Google 登录块中描述的方法,但它仍然给了我相同的消息

UPDATE: As of January 2021, this no longer works.更新:截至 2021 年 1 月,这不再有效。

I know this is quite a late answer, but Selenium can already do this (by exploiting a bypass).我知道这是一个很晚的答案,但是 Selenium 已经可以做到这一点(通过利用旁路)。

By default, Google detects and effectively blocks all logins from Selenium webdriver.默认情况下,Google 会检测并有效阻止来自 Selenium webdriver 的所有登录。

The following link comes from the Google OAuth Playground, ensuring the practicality of the link.以下链接来自Google OAuth Playground,保证链接的实用性。 It most likely won't expire any time soon.它很可能不会很快到期。

https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718192.apps.googleusercontent.com&scope=email&access_type=offline&flowName=GeneralOAuthFlow https://accounts.google.com/o/oauth2/v2/auth/oauthchooseaccount?redirect_uri=https%3A%2F%2Fdevelopers.google.com%2Foauthplayground&prompt=consent&response_type=code&client_id=407408718&192e.comaccess.离线&flowName=GeneralOAuthFlow

You can use that link (ie. driver.get() ) to log into your Google account.您可以使用该链接(即driver.get() )登录您的 Google 帐户。

This bypasses the automation checks allows you to log into Google using Selenium.这绕过了自动化检查,允许您使用 Selenium 登录 Google。 At least for now.至少现在。

If this helped you, please mark it as the accepted answer.如果这对您有帮助,请将其标记为已接受的答案。 It will help others who have this question.它将帮助其他有这个问题的人。

UPDATE: As of January 2021, this no longer works.更新:截至 2021 年 1 月,这不再有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM