使用 python 和 selenium 的自动化 Google 登录显示““此浏览器或应用程序可能不安全””

新手上路,请多包涵

我已尝试使用 Gmail 或任何 Google 服务登录,但它显示以下消息“此浏览器或应用程序可能不安全”:

错误图片

我还尝试做一些选项,比如在我的账户中启用安全性较低的应用程序,但它没有用。然后我创建了一个新的谷歌帐户并且它与我一起工作。但不是我的旧帐户。

  1. 我该如何解决这个问题?

  2. 我如何在普通的 chrome 浏览器中打开 selenium 而不是由自动化软件控制的浏览器?

这是我的代码

    from selenium.webdriver import Chrome
    from selenium.webdriver.chrome.options import Options

    browser = webdriver.Chrome()
    browser.get('https://accounts.google.com/servicelogin')
    search_form = browser.find_element_by_id("identifierId")
    search_form.send_keys('mygmail')
    nextButton = browser.find_elements_by_xpath('//*[@id ="identifierNext"]')
    search_form.send_keys('password')
    nextButton[0].click()

原文由 Abdulrahman Dawoud 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 5.2k
2 个回答

首先不要使用 chrome 和 chromedriver。您需要使用 Firefox。(如果未安装)下载并安装 Firefox。使用普通的 Firefox 登录 Google。

你需要向谷歌网站表明你不是机器人。您可以使用这样的代码:

 from selenium import webdriver
import geckodriver_autoinstaller
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

geckodriver_autoinstaller.install()

profile = webdriver.FirefoxProfile(
    '/Users/<user name>/Library/Application Support/Firefox/Profiles/xxxxx.default-release')

profile.set_preference("dom.webdriver.enabled", False)
profile.set_preference('useAutomationExtension', False)
profile.update_preferences()
desired = DesiredCapabilities.FIREFOX

driver = webdriver.Firefox(firefox_profile=profile,
                           desired_capabilities=desired)

可以帮助您找到您的个人资料位置。

但是,为什么是 Firefox?

其实只有一个原因,chromedriver 是谷歌编码的。他们可以很容易地了解它是否是机器人。但是当我们用 Firefox 添加用户数据时,他们无法理解是否有 bot。

你可以这样愚弄谷歌。它也对我有用。我非常努力地做到这一点。希望它也能在你身上得到解决。

原文由 yusufusta 发布,翻译遵循 CC BY-SA 4.0 许可协议

这对我有用。我从 GitHub 找到了解决方案。

    from selenium import webdriver
   from selenium_stealth import stealth

   options = webdriver.ChromeOptions()
   options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36")
   options.add_experimental_option("excludeSwitches", ["enable-automation"])
   options.add_experimental_option('useAutomationExtension', False)
   options.add_argument('--disable-blink-features=AutomationControlled')
   driver = webdriver.Chrome(options=options)
   stealth(driver,
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )
   driver.get("https://www.google.com")

原文由 Praveen Kumar 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题