urllib2 login help

J

john.weatherwax

Hello,

I'm having trouble using urllib2 (maybe) when trying to log into a web
site that requires a user to enter a login name and a password
(authentication). I've tried many things but none seem to work and
have become stuck recently and was hoping to get a hint from those
much more knowledgeable than myself.

I want to automate logging on to the investopedia stock simulator web
site.

http://simulator.investopedia.com/authorization/login.aspx

I can't seem to automate this successfully.

My python script is below:

import os,re
import urllib, urllib2

theurl = "http://simulator.investopedia.com/authorization/login.aspx"

post_dict = { "ct100$MainPlaceHolder$usernameText": "XXX",
"ct100$MainPlaceHolder$passwordText": "XXX", "ct100$MainPlaceHolder
$loginButton": "Sign In", "ct100$MainPlaceHolder$rememberMeCheckBox":
"on" }

post_data = urllib.urlencode( post_dict )

headers = { 'User-agent': 'Mozilla/4.0 (compatible; MSIE 5.5; Windows
NT)',
'Host': 'simulator.investopedia.com',
'Referer': 'http://simulator.investopedia.com/
authorization/login.aspx',
}

req = urllib2.Request( theurl, post_data, headers )
response = urllib2.urlopen(req)
the_page = response.read()

The problem is that this page returned seems to be the same as the
login page which I connected to initially. When I perform the login
process manually things work as expected. What am I doing
incorrectly?

*ANY* hints/suggestions/directions would be very appreciated since
I've run out of ideas of things to try at this point.

Thanks very much
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top