Python Forum
I have a problem saving the file in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I have a problem saving the file in python
#1
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')
Reply
#2
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()
Reply
#3
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
Reply
#4
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.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020