Iterate through a list and try log in to a website with urllib and re

Marcus marcuscvj at
Mon Mar 3 13:32:39 CET 2014


I'm trying to use urllib and urllib2 to open an url + login_data in a for loop. How can I display when successfully logged in and how to show when the login is denied? 

I've tried use this:

html_content = urllib2.urlopen(url).read()
re.findall('ERROR: The password you entered for the username USER is incorrect.', html_content)

1. I want to try an if statement in a for loop
2. Iterate through a list and when the first password in the list is denied. It shall continue with the next password in the list and try that one.
3. When it's successfully logged in the program will stop the loop and print out the password that matches.

I'm stuck and need some help creating this.

More information about the Python-list mailing list