繁体   English   中英

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

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

我一直在尝试使用 selenium 登录我的谷歌帐户,但是一旦我传入 email 并按回车键,它就会重定向到以下消息

“此浏览器或应用程序可能不安全。了解更多尝试使用其他浏览器。如果您已经在使用受支持的浏览器,则可以刷新屏幕并再次尝试登录。”

这是我的 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)

请注意,我是 python 和 selenium 的新手。 非常感谢您的帮助。 先感谢您

我尝试使用Selenium Google 登录块中描述的方法,但它仍然给了我相同的消息

更新:截至 2021 年 1 月,这不再有效。

我知道这是一个很晚的答案,但是 Selenium 已经可以做到这一点(通过利用旁路)。

默认情况下,Google 会检测并有效阻止来自 Selenium webdriver 的所有登录。

以下链接来自Google OAuth Playground,保证链接的实用性。 它很可能不会很快到期。

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

您可以使用该链接(即driver.get() )登录您的 Google 帐户。

这绕过了自动化检查,允许您使用 Selenium 登录 Google。 至少现在。

如果这对您有帮助,请将其标记为已接受的答案。 它将帮助其他有这个问题的人。

更新:截至 2021 年 1 月,这不再有效。

暂无
暂无

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

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