所以,这就是我想要做的......
error = driver.find_element_by_xpath("""//*[@id="MemberNameError"]""")
if error.is_displayed():
print(line.strip() + " is taken")
else:
print(line.strip() + " is available")
with open("emails_available.txt", "a") as email_txt:
email_txt.write(line.strip() + "@hormail.com" + "\n")
如果电子邮件可用,我该如何制作,然后写入txt
答案 0 :(得分:1)
如何将if / else放在with?
中error = driver.find_element_by_xpath("""//*[@id="MemberNameError"]""")
with open("emails_available.txt", "a") as email_txt:
if error.is_displayed():
print(line.strip() + " is taken")
else:
print(line.strip() + " is available")
email_txt.write(line.strip() + "@hormail.com" + "\n")
我认为这里可能存在一个循环,你没有包括......也可以进入with
语句。