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

M

Marcus

Hello,

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.
 
C

Chris Angelico

So basically, you're doing a dictionary attack. May I ask why you're
doing this, exactly?

oops, misclicked.

I note that the user name 'alex' does not appear to match your name.
I'm going to want a good reason for this code to be written, else
you're on your own - I don't intend to help you steal someone else's
password.

ChrisA
 
M

Marcus

Yes, it's only for my own use on my local WordPress installation. Only educational use.
 
C

Chris Angelico

Yes, it's only for my own use on my local WordPress installation. Only educational use.

What are you trying to learn, exactly? How to break into a WP site?

Still dubious.

ChrisA
 
M

Marcus

It's not that hard to find a program that does this already. But I'm tryingto learn how to use these modules to create this. I've started it and now i want to complete it so I can create another program and learn more about other stuff, maybe a Twitter script or something. How do I learn when not practice?
 
R

Roy Smith

Marcus said:
I'm trying to use urllib and urllib2 to open an url + login_data in a for
loop.

Step 1: Ignore all that crap and get http://www.python-requests.org/
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)

In the ideal case, whatever you're talking to will return a success or
failure indication in the HTTP status code.

Lacking that, it will at least return something intended to be parsed
(like JSON).

Lacking that (and, unfortunately, common), you're reduced to
screen-scraping. But, if you've got to do that, at least use a tool
like lxml or BeautifulSoup to parse the HTML.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top