Python登录到需要MFA令牌的网站
我正在尝试为我的工作创建一个登录工具,该工具将使我登录到各种站点,在3分钟不活动后将我注销。我已经让它在许多网站上运行,但没有一个网站需要MFA令牌。我目前使用谷歌验证器,但也可以使用电子邮件,或几个不同的选项。我该如何以编程方式获取该代码以使登录过程更快?我正在使用Selenium,因为我需要在登录后使用该网页。以下是我迄今为止的代码:Python登录到需要MFA令牌的网站,python,selenium,authentication,automation,Python,Selenium,Authentication,Automation,我正在尝试为我的工作创建一个登录工具,该工具将使我登录到各种站点,在3分钟不活动后将我注销。我已经让它在许多网站上运行,但没有一个网站需要MFA令牌。我目前使用谷歌验证器,但也可以使用电子邮件,或几个不同的选项。我该如何以编程方式获取该代码以使登录过程更快?我正在使用Selenium,因为我需要在登录后使用该网页。以下是我迄今为止的代码: def loginsys(): driver = webdriver.Chrome('C:/path/to/chromedriver.exe')
def loginsys():
driver = webdriver.Chrome('C:/path/to/chromedriver.exe')
driver.get('https://www.specifiedurl.com/login')
username = driver.find_element_by_id('txtUsername')
password = driver.find_element_by_id('txtPassword')
username.send_keys("myusername")
password.send_keys("mypassword")
driver.find_element_by_name('btnLogin').click()
### This is where I need to do MFA as it will not pull the next page without it
driver.get('https://www.specifiedurl.com/page/after/login')
想法?(显然,这不是url,也不是我的实际用户名或密码)检查
pyotp
库。您可以获得与google身份验证关联的MFA密钥,如下所示
from pyotp import *
# get the token from google authentication
totp = TOTP("your 16 character security token goes here")
token = totp.now()
print (token)
# now you can use token in your script
检查
pyotp
库。您可以获得与google身份验证关联的MFA密钥,如下所示
from pyotp import *
# get the token from google authentication
totp = TOTP("your 16 character security token goes here")
token = totp.now()
print (token)
# now you can use token in your script