python - Using a email list from .txt file to cycle through and test logins? -


basically have list of emails on .txt file. goal run through each of them 1 one , test see if accounts valid. i'm trying set in code set variable go 1 one login = email[0].format(start + i). in theory change selection of emails in list. each time new email selected run code email. seems pick [0] every time, correct method i'm trying obtain? if not able point in more efficient method of obtaining each email run in code?

i thinking may should try login = email[num] error asking integer not string. advice on direction go appreciated.

code

import requests import time  start = 1 #while true: in range(500):     password = 'abcdefg'     num = ('{0}').format(start + i)      open('email.txt') email_text:         email = email_text.read().splitlines()      login = email[0].format(start + i)     #login = email[num]      app_version = '100'     experience = '200'      session = requests.session()     session.headers.update({         'user-agent': 'mozilla/5.0 (macintosh; intel mac os x 10_10_5) applewebkit/537.36 (khtml, gecko) chrome/53.0.2785.116 safari/537.36'     })     session.get('https://www.nike.com/snkrs/')     try:         print(login)         print('logging in...')         login_data = {             'username': login,             'password': password,             'keepmeloggedin': true,             'client_id': 'hfkjshfkjshfkjshdf',             'ux_id': 'com.nike.commerce.snkrs.web',             'grant_type': 'password'         }         login_params = {             'appversion': app_version,             'experienceversion': experience,             'uxid': 'com.nike.commerce.snkrs.web',             'locale': 'en_us',             'backendenvironment': 'identity',             'browser': 'google inc.',             'os': 'undefined',             'mobile': 'false',             'native': 'false'         }         login_url = 'https://unite.nike.com/loginwithsetcookie'          login_res = session.post(login_url, json=login_data, params=login_params)         time.sleep(1)     except:         pass         time.sleep(1)         access_token = none     try:         access_token = login_res.json()['access_token']     except valueerror:         print('could not login.')     except keyerror:         print('could not login.')     if not access_token:         quit()      print('logged in.')      print('getting address info...')      get_address_params = {         'appversion': app_version,         'experienceversion': experience,         'uxid': 'com.nike.commerce.snkrs.web',         'locale': 'en_us',         'backendenvironment': 'identity',         'browser': 'google inc.',         'os': 'undefined',         'mobile': 'false',         'native': 'false',         'viewid': 'commerce',         'token': access_token     }     get_address_url = 'https://unite.nike.com/getuserservice'     get_address_res = session.get(get_address_url, params=get_address_params)     print('retreived address info.')      verified = 'verifiedphone' in get_address_res.json()     print('verified: '+str(verified)) 

do not open , close file on every loop. (pseudo code):

with open('file.txt') f:     list = f.readlines()      email in list:         check_login(email) 

note: email string in line, index not needed


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -