Selify Google登录在自动化中被阻止 [英] Selenium Google Login Blocked in Automation

查看:0
本文介绍了Selify Google登录在自动化中被阻止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从今天起,用户不能在新配置文件中登录Google帐户。我发现,谷歌正在阻止这一进程(拒绝?)即使是在尝试Stackauth的时候。(更新到V90后遇到此问题)。

这是我之前使用OAuth为Google登录发布的answer,直到最近才恢复正常!
简而言之,您将通过stackauth直接登录。

  • 我绕过这些限制的唯一方法是禁用安全应用程序访问或添加以下给定参数。(我不喜欢这样做,因为我无法说服使用我的应用程序的用户(100+)禁用它!)
    options.add_argument('user-data-dir=C:/Users/{username}/path to data of browser/')
  • 另一种唯一的登录方式是使用隐身功能将用户代理伪装到前面提到的here,效果很好。
  • 我发现的主要缺点是在自动化运行时无法打开另一个选项卡,否则该过程将中断。但这与这一缺点完美地结合在一起。
  • 但我发现的缺点是,一旦登录,您就无法完成工作,因为您访问的网站会限制您,并迫使您更新浏览器才能访问网站(在我的情况下是Google Meet)。 另一方面,理论上,人们可以用用户数据打开自动化,但在新的窗口中。与除OAuth之外的其他方法相比,我觉得这是非常理想的,因为这是最好的方法。

还有没有其他最佳的工作建议来绕过Google的这些限制?

推荐答案

最后,我成功地绕过了Selify中的Google安全限制,希望它也能对您有所帮助。在此共享完整代码。

简而言之:

  • 您需要使用旧的/过时的用户代理并还原。

详细信息:

  • 使用selenium-stealth伪造用户代理。
  • 在登录前将用户代理初始设置为DN
  • 然后,登录后恢复正常。(不是真的,但Chrome v>;80) 就是这样。
    无需保留用户数据启用安全性较低的应用程序访问,无需任何操作!

这是我当前工作的代码片段,非常长!.(为了更好地理解,请附上注释)。

# Import required packages, modules etc.. Selenium is a must!

def login(username, password):       # Logs in the user
    driver.get("https://stackoverflow.com/users/login")
    WebDriverWait(driver, 60).until(expected_conditions.presence_of_element_located(
        (By.XPATH, '//*[@id="openid-buttons"]/button[1]'))).click()

    try:
        WebDriverWait(driver, 60).until(expected_conditions.presence_of_element_located(
            (By.ID, "Email"))).send_keys(username)      # Enters username
    except TimeoutException:
        del username
        driver.quit()
    WebDriverWait(driver, 60).until(expected_conditions.element_to_be_clickable(
        (By.XPATH, "/html/body/div/div[2]/div[2]/div[1]/form/div/div/input"))).click()      # Clicks NEXT
    time.sleep(0.5)

    try:
        try:
            WebDriverWait(driver, 60).until(expected_conditions.presence_of_element_located(
                (By.ID, "password"))).send_keys(password)       # Enters decoded Password
        except TimeoutException:
            driver.quit()
        WebDriverWait(driver, 5).until(expected_conditions.element_to_be_clickable(
            (By.ID, "submit"))).click()     # Clicks on Sign-in
    except TimeoutException or NoSuchElementException:
        print('
Username/Password seems to be incorrect, please re-check
and Re-Run the program.')
        del username, password
        driver.quit()

    try:
        WebDriverWait(driver, 60).until(lambda webpage: "https://stackoverflow.com/" in webpage.current_url)
        print('
Login Successful!
')
    except TimeoutException:
        print('
Username/Password seems to be incorrect, please re-check
and Re-Run the program.')
        del username, password
        driver.quit()

USERNAME = input("User Name : ")
PASSWORD = white_password(prompt="Password  : ")      # A custom function for secured password input, explained at end.

# Expected and required arguments added here.
options = Options()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
options.add_experimental_option('excludeSwitches', ['enable-logging'])

# Assign drivers here.

stealth(driver,
        user_agent='DN',
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )       # Before Login, using stealth

login(USERNAME, PASSWORD)       # Call login function/method

stealth(driver,
        user_agent='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.72 Safari/537.36',
        languages=["en-US", "en"],
        vendor="Google Inc.",
        platform="Win32",
        webgl_vendor="Intel Inc.",
        renderer="Intel Iris OpenGL Engine",
        fix_hairline=True,
        )       # After logging in, revert back user agent to normal.

# Redirecting to Google Meet Web-Page
time.sleep(2)
driver.execute_script("window.open('https://the website that you wanto to go.')")
driver.switch_to.window(driver.window_handles[1])       # Redirecting to required from stackoverflow after logging in
driver.switch_to.window(driver.window_handles[0])       # This switches to stackoverflow website
driver.close()                                          # This closes the stackoverflow website
driver.switch_to.window(driver.window_handles[0])       # Focuses on present website

单击here了解白色密码。

这篇关于Selify Google登录在自动化中被阻止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆