我正在做一个roblox名称检查器。只有代码有效。
我已经尝试过像f:等使用open(...)
with open('usernames.txt') as f:
for line in f:
a=requests.get('https://api.roblox.com/users/get-by-username?username=%s' % line)
r=json.loads(a.content)
try:
if r["success"]== False:
print("Username avaliable ["+line+"]")
f=open("free.txt",'a')
f.write('n')
f.close()
except:
print("Username taken ["+line+"]")
file=open("taken.txt",'a')
file.write(line)
file.close()
答案 0 :(得分:0)
打开文件:
with open('usernames.txt', 'r') as file:
data = file.readlines()
现在,数据是每一行的列表,因此您可以对其进行迭代
for i in range(0,len(data)):
username = data[i].replace("\n","")
a=requests.get('https://api.roblox.com/users/get-by-username?username=%s' % username)
r=json.loads(a.content)
try:
if r["success"]== False:
print("Username avaliable ["+username+"]")
f=open("free.txt",'a')
f.write(username + "\n")
f.close()
except:
print("Username taken ["+username+"]")
file=open("taken.txt",'a')
file.write(username + "\n")
file.close()
尝试这种方式;用户名变量用于在每行末尾添加“输入”。