首页 > 解决方案 > 从 txt 文件中跳过一行

问题描述

您好,我想从我的 txt 文件中发送一个随机密钥,如果有空行则跳过我的问题是我的代码只发送一个字母而不是整行

这是我的代码

with open('list.txt', 'r', encoding='utf-8') as f:
        file = f.readline()
    for word in file:
        if not word.strip():
            continue
        elif not 0 < len(word) < 280:
            continue

sleep(1)
        
        driver.find_element_by_css_selector('div[role="textbox"][data-testid="tweetTextarea_0"]').send_keys(random.choice(word))

        sleep(1)

标签: pythonseleniumlinetxt

解决方案


推荐阅读