Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grab username:password from text file, then post into login form

Tags:

python

file

I have a text file with usernames and passwords. The text file is formatted like this:

username1:password1
username2:password2
username3:password3

I want to grab the first line, split it to "username1" and "password1", and then post to this:

br.form['login'] = 'username1'
br.form['passwd'] = 'password1'

After that, I want it to repeat and move onto username2:password2.

How can this be done?

like image 271
Shtoops Avatar asked Jan 30 '12 02:01

Shtoops


1 Answers

Assuming no : characters in your usernames or passwords:

with open('myfile.txt') as f:
    credentials = [x.strip().split(':', 1) for x in f]

for username, password in credentials:
    # your code here 
like image 71
wim Avatar answered Sep 23 '22 07:09

wim