为什么两个用户名被附加到列表中,而不是一个

Why are two usernames being appended to list instead of one

提问人:Jonathan Bankston 提问时间:10/22/2023 更新时间:10/22/2023 访问量:41

问:

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

我尝试创建一个 while 循环来检查用户名是否已经在列表中,但是,即使用户名是唯一的,这似乎也会创建一个永无止境的 while 循环。我最初使用基本的文件 io 逻辑来写入文件,但我切换到 pandas,这导致我首先发现了这个问题。我还试图看看聊天 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 列表 自动化 自动完成

评论

2赞 Community 10/22/2023
请澄清您的具体问题或提供其他详细信息,以准确说明您的需求。正如目前所写的那样,很难确切地说出你在问什么。

答: 暂无答案