You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Selenium自动化登录谷歌账号触发安全拦截报错的问题咨询

问题判定

你遇到的 "Couldn't sign you in, this browser or app may not be secure" 提示是谷歌账号体系的官方自动化风控拦截,不是代码语法错误导致的。
触发拦截的核心原因有两个:

  • Selenium默认启动的Chrome实例会携带明确的自动化控制特征(包括navigator.webdriver标记、默认启动参数指纹等),谷歌登录页的风控脚本会直接识别这类非真人操作的浏览器环境,直接阻断登录流程,不会进入密码校验环节。
  • 你实现的是1-100000区间的密码枚举逻辑,属于典型的暴力破解行为,就算躲过基础的浏览器特征检测,短时间内多次提交错误密码也会触发更高等级的风控拦截。
现有代码的逻辑问题

你的代码除了触发风控之外,本身存在多个会导致运行失败的逻辑缺陷:

  • 全局变量未初始化:guessCount、cracked仅做了全局声明,没有赋值初始值,运行时会直接抛出未定义错误。
  • 元素检测逻辑完全失效:Selenium的find_element方法在找不到目标元素时会直接抛出NoSuchElementException,不会返回None,你写的if driver.find_element(...) is not None判断逻辑永远不会按预期执行,页面缺少对应元素时代码会直接崩溃。
  • 验证码处理逻辑无效:你用requests单独拉取验证码图片时没有携带当前浏览器会话的Cookie,拿到的验证码和当前登录会话不匹配;同时pytesseract对谷歌的扭曲字符验证码识别率极低,根本无法通过校验。
  • 依赖导入缺失:代码没有导入selenium.webdriver模块,运行时会直接报webdriver未定义错误。
关于绕过方案的说明

注意:对他人账号进行暴力猜解属于违法行为,同时严重违反谷歌服务条款,以下仅做技术原理说明,不提供任何可用于未授权账号访问的绕过方法。

不存在稳定可用的长期绕过方案:

  • 谷歌登录风控是基于浏览器指纹、操作行为特征、IP信誉、账号历史登录数据多维度判定的,仅靠修改Selenium启动参数、隐藏webdriver标记这类基础手段,只能躲过最表层的检测,一旦开始批量提交错误密码,会立刻触发二次拦截。
  • 你遇到的这类“浏览器不安全”提示属于高风险等级的拦截,即便你使用真实用户的Chrome配置文件、切换住宅IP、添加随机操作延迟,只要密码错误次数达到风控阈值,依然会被阻断登录流程。
相关附件

登录报错截图

原提问附代码:

from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import pytesseract
import requests

# Setup global variables
global guessCount
global cracked
global driver


def enterEmail():
    global cracked
    driver.implicitly_wait(2)
    email = driver.find_element(By.ID, "identifierId")
    email.send_keys('testacc3644@gmail.com' + Keys.RETURN)
    driver.implicitly_wait(3)
    cracked = 'true'


def defeat_recaptcha():
    global cracked
    driver.implicitly_wait(6)
    captcha_img_element = driver.find_element(By.ID, "captchaimg")
    captcha_img_link = captcha_img_element.get_attribute("src")
    print(captcha_img_link)
    img = requests.get(captcha_img_link, stream=True)
    cracked = 'true'
    # Process image
    word = pytesseract.image_to_string(img)
    print(word)
    # Get captcha box
    code = driver.find_element(By.ID, "ca")
    code.send_keys(word + Keys.RETURN)
    cracked = 'true'


def main():
    global driver
    driver = webdriver.Chrome()
    driver.get('https://accounts.google.com/signin/v2/identifier?elo=1&flowName=GlifWebSignIn&flowEntry=ServiceLogin')


    enterEmail()
    while cracked == 'true':
        driver.implicitly_wait(5)
        if driver.find_element(By.ID, "captchaimg") is not None:
            # run inside loop to crack recaptcha
            defeat_recaptcha()
        if driver.find_element(By.NAME, 'password') is not None:
            passwd = driver.find_element(By.NAME, 'password')
            guess = 10000 + guessCount
            guessCount = guessCount + 1
            inputGuess = str(guess) + '000'
            passwd.send_keys(inputGuess + Keys.RETURN)
            passwd.clear()
            # Get captcha image
        print(guess)


if __name__ == "__main__":
    main()

内容的提问来源于stack exchange,提问作者Dylan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.28 11:48:26