为什么将两个用户名而不是一个添加到列表中

问题描述 投票:0回答:1

我认为列表逻辑存在问题,我的代码生成随机用户名和密码,然后将它们附加到单独的用户名和密码列表中,但是,当我打印出此列表时,代码似乎要么使用相同的值填充两个索引用户名,或交替使用一两个相同的用户名,但是,密码列表的格式似乎正确。任何帮助将不胜感激。

我尝试创建一个 while 循环来检查用户名是否已在列表中,但是,即使用户名是唯一的,这似乎也创建了一个永无止境的 while 循环。我最初使用基本的文件 io 逻辑写入文件,但我切换到 pandas,这导致我首先发现了这个问题。我也尝试看看 chat gpt 是否有任何解决方案,但模型说我的代码似乎是正确的(尽管我对此持保留态度)。

usernames = []
passwords = []
emails = []
email_names = ['alpha',
                'omega',
                'ruby',
                'sapphire',
                'omegraruby',
                'alphasaphhire',
                'artreus',
                'kratos',
                'leai']


def create_acc():
    
    user_input = int(input('Enter the number of accounts you would like to create: '))
    for i in range(user_input):

        time_stamp = time.time()
        url = 'https://www.reddit.com/account/register/'
        driver.get(url)
        driver.maximize_window()

        email_name = random.choice(email_names)
        username = generate_username(name_of_user = email_name)
        password = pw_gen()
        usernames.append(username)
        passwords.append(password)
        print(usernames)
        print(username)
        
        #username index 0 matches with password index 0
        
        wait = WebDriverWait(driver, 10)
        wait.until(EC.presence_of_element_located((By.ID, 'regEmail')))
        wait.until(EC.element_to_be_clickable((By.ID, 'regEmail')))
        wait.until(EC.presence_of_element_located((By.TAG_NAME, 'button')))

        submit_btn = wait.until(EC.element_to_be_clickable((By.TAG_NAME, 'button')))

        email_field = driver.find_element(By.NAME, 'email')
        time.sleep(1)
        email_field.send_keys(rand_email())
        time.sleep(5)
        submit_btn.click()

        user_field = wait.until(EC.presence_of_element_located((By.NAME, 'username')))
        wait.until(EC.element_to_be_clickable((By.NAME, 'username')))

        pswd_field = wait.until(EC.presence_of_element_located((By.NAME, 'password')))
        wait.until(EC.element_to_be_clickable((By.NAME, 'password')))

        wait.until(EC.presence_of_element_located((By.TAG_NAME, 'button')))
        signup_btn = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div/main/div[2]/div/div/div[3]/button')))

        time.sleep(1)
        user_field.send_keys(username)
        time.sleep(1)
        pswd_field.send_keys(password)
        
    print('Account creation complete')

python-3.x pandas list automation autocomplete
1个回答
0
投票

您的代码中的列表逻辑可能存在问题。该代码生成随机用户名和密码,然后将它们附加到单独的用户名和密码列表中。但是,当您打印出用户名列表时,代码似乎要么使用相同的用户名填充两个索引,要么在一个和两个相同的用户名之间交替,而密码列表似乎格式正确

© www.soinside.com 2019 - 2024. All rights reserved.