gpt4 book ai didi

python - For Loop in python x文件中的次数

转载 作者:行者123 更新时间:2023-11-28 21:40:53 25 4
gpt4 key购买 nike

脚本针对 accounts.txt 文件中存在的帐户数量运行。我想运行脚本 x 次,无论 accounts.txt 文件中存在多少个帐户。所以我只输入一个输入 10,脚本应该只运行 10 次 for 循环。下面是我的代码。

有人可以帮我解决如何修复 for 循环或为 for 循环添加新的父级吗?

file = open('accounts.txt','r')

for line in file:
credentials = line.split(";")
username = credentials[0]
password = credentials[1]
comment = credentials[2]

chromedriver = "/Users/Ali/Downloads/chromedriver"

os.environ["webdriver.chrome.driver"] = chromedriver
# driver = webdriver.Chrome(chromedriver)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--mute-audio")

最佳答案

这应该有效:

for count, line in enumerate(file):
credentials = line.split(";")
username = credentials[0]
password = credentials[1]
comment = credentials[2]

chromedriver = "/Users/Ali/Downloads/chromedriver"

os.environ["webdriver.chrome.driver"] = chromedriver
# driver = webdriver.Chrome(chromedriver)
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--mute-audio")

if count == 9: # count starts at 0
break

关于python - For Loop in python x文件中的次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45198814/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com