使用Python和Selenium,如何绕过双因素身份验证?

2024-05-18 09:40:35 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的密码:

from selenium import webdriver
import time



x = 0

#while x < 5:

browser = webdriver.Chrome('/Users/John Smith/Downloads/chromedriver.exe')

browser.get('https://kdp.amazon.com/en_US/')

x = 0  


def Sign():

    browser.find_element_by_id('signinButton-announce')

    elem = browser.find_element_by_id('signinButton-announce')
    elem.click()

    email = browser.find_element_by_id('ap_email')
    email.send_keys(' ')

    password = browser.find_element_by_id('ap_password')
    password.send_keys(' ')

    SignIn = browser.find_element_by_id('signInSubmit')
    SignIn.click()

def Sign1():

    browser.find_element_by_id('signinButton-announce')

    elem = browser.find_element_by_id('signinButton-announce')
    elem.click()

    email = browser.find_element_by_id('ap_email')
    email.send_keys(' ')

    password = browser.find_element_by_id('ap_password')
    password.send_keys(' ')

    SignIn = browser.find_element_by_id('signInSubmit')
    SignIn.click()
    browser.execute_script("window.open('https://kdp.amazon.com/en_US/', 'new window')")
Sign()


time.sleep(20)

browser.execute_script("window.open('https://kdp.amazon.com/en_US/', 'new window')")

if (browser.current_url == 'https://kdp.amazon.com/en_US/'):
    Sign1()
    x += 1

我试图通过创建另一个选项卡来解决这个问题,因此如果我输入一次身份验证代码,也许之后它就不再需要它了。我真的找不到办法解决这个。。有办法吗?你知道吗

我听说过使用当前的chrome配置文件,但是我找不到一种方法来实际使用它上的任何命令。我已经有了chrome文件,但它不会去的网址,我需要它去。你知道吗


Tags: httpsbrowsercomidamazonbyemailpassword