I have a problem saving the file in python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: I have a problem saving the file in python (/thread-23381.html) |
I have a problem saving the file in python - abdlwafitahiri - Dec-26-2019 I have a problem saving the file When it is finished, tell me it is finished and go see the LIVE.txt file I find it empty, even though it tells me it was saved .. from selenium import webdriver import time live = open('LIVE.txt', 'w') die = open('DIE.txt', 'w') list = input("Input Mail List :") while True: driver = webdriver.Chrome() driver.maximize_window() list = open(list, 'r').readlines() for line in list: email = line.strip() driver.get("https://www.etsy.com/forgot_password?email=") checkemail = driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[2]/form/div/input[1]') checkemail.send_keys(list) loginButton = driver.find_elements_by_css_selector("#submit-button") loginButton[0].click() emailcheck = driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[1]') if emailcheck == driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[1]') : print("\033[32;1mLIVE\033[0m | " + email + " | [(Checked)]") live.write(email + '\n') else: print("\033[31;1mDIE\033[0m | " + email + " | [(Checked)]") die.write(email + '\n') RE: I have a problem saving the file in python - snippsat - Dec-26-2019 Need to close file before anything get written. Here also trow in f-string as a example. if emailcheck == driver.find_element_by_xpath('//*[@id="content"]/div/div/div/div[1]'): print(f"\033[32;1mLIVE\033[0m | {email} | [(Checked)]") live.write(f'{email}\n') live.close() RE: I have a problem saving the file in python - abdlwafitahiri - Dec-26-2019 He gave me this problem .. Traceback (most recent call last): File "<input>", line 1, in <module> File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\_pydev_bundle\pydev_umd.py", line 197, in runfile pydev_imports.execfile(filename, global_vars, local_vars) # execute the script File "C:\Program Files\JetBrains\PyCharm Community Edition 2019.3.1\plugins\python-ce\helpers\pydev\_pydev_imps\_pydev_execfile.py", line 18, in execfile exec(compile(contents+"\n", file, 'exec'), glob, loc) File "C:/Users/abdlwafitahiri/Desktop/Python/cours 1.py", line 21 print(f"\033[32;1mLIVE\033[0m | {email} | [(Checked)]") ^ SyntaxError: invalid syntax RE: I have a problem saving the file in python - snippsat - Dec-26-2019 Try the older .foramt() method.print("\033[32;1mLIVE\033[0m | {} | [(Checked)]".format(email))You should upgrade python version,recommend Python 3.7 or newer. f-string was new in Python 3.6,which was the biggest version upgrade for Python 3.
|