Urllib and login

M

Massi

Hi everyone, I'm trying to get data from an internet page which is
accessed from a login page. Looking at the html source code of the
login page I found that the name of the controls which handle username
and password are "login_un" and "login_pw". So I tried to write a
piece of code to access the data of the protected page:

import urllib2, urllib

opener = urllib2.build_opener()
login_data = urllib.urlencode({"login_un" : "my_un", "login_pw" :
"my_pw"})
opener.open('http://www.myprotectedsite.com/login_page', login_data)
resp = opener.open('http://www.myprotectedsite.com/hidden_page')
print resp.read()

But it doesn't work, since it prints the html code of the login page.
Can anyone point me out what I'm doing wrong?
Thanks in advance.
 

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,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top