如何使用selenium python登录google帐户

2024-04-24 10:09:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试使用selenium登录我的google帐户,但一旦我传入电子邮件并点击enter,它就会重定向到以下消息

"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."

以下是我的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 Login Block中描述的方法,但它仍然给了我同样的信息


Tags: tobrowseryousendemaildriverseleniumgoogle
1条回答
网友
1楼 · 发布于 2024-04-24 10:09:57

硒已经可以做到这一点(通过利用旁路)

默认情况下,Google检测并有效阻止SeleniumWebDriver的所有登录

以下链接来自GoogleOAuth游乐场,确保了链接的实用性。它很可能不会很快过期

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

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

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

更新:自2021年1月起,此功能不再有效

相关问题 更多 >