我想使用硒登录到我的Gmail帐户。我使用python2.7。它没有错误,但是页面上说由于某些原因我无法登录我的帐户。您可以在下面看到屏幕截图。
这是我的代码:
import time
import selenium
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
EXE_PATH = r'C:\Users\LENOVO\Downloads\geckodriver.exe'
driver = webdriver.Firefox(executable_path=EXE_PATH)
def login():
mail = 'myMail'
pw = 'myPassword'
driver.get('https://gmail.com')
email = driver.find_element_by_name('identifier')
email.send_keys(mail)
driver.find_element_by_id('identifierNext').click()
time.sleep(10)
password = driver.find_element_by_name('password')
password.send_keys(pw)
driver.find_element_by_id('passwordNext').click()
我该怎么办?请帮助我,我只是菜鸟和初学者。谢谢师父
这似乎是自动登录的已知问题。
如果要继续这样做,您需要在Gmail帐户中启用安全性较低的应用程序。
https://myaccount.google.com/lesssecureapps
此设置可能不适用于:
启用了两步验证的帐户:此类帐户需要特定于应用程序的密码才能降低应用程序的安全性。G Suite用户:如果您的管理员锁定了不太安全的应用程序帐户访问权限,此设置将被隐藏。
此错误屏幕...
...表示WebDriver无法认证Browsing Context,即Browser会话。
[文章"This browser or app may not be secure" error when trying to sign in with Google on desktop apps中的Raphael Schaad提到:
[如果用户可以使用其他Google帐户登录到同一应用程序,那么问题一定出在特定帐户上。
可能的原因,这是用户正在使用双因素身份验证的唯一帐户。
为此Google帐户禁用双重身份验证并执行您的@ Test
Sign in with a supported browser
尝试以下解决方案:
代码块:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=options, executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe')
driver.get("https://www.gmail.com")