web log in using python

Posted by Prashanth Mohan on Tue 22 Nov 2005 12:41 PM — 4 posts, 19,818 views.

#0

Hello

I am new to python programming. I want to do a project which calculates the broadband usage for a particular ISP. How can i get the pages after logging into a website?

i understand that i will have to use the urllib2 library. I have been trying to read the docs, but however i could not figure out how to use it's functions.

How can i pass username, password to a website and get the logged in webpage? also this site works only for IE, so i will have to set the user string too.

Thank You

Prashanth
#1
Something like this perhaps? I got it from the Python Manual.


import urllib2
# Create an OpenerDirector with support for Basic HTTP Authentication...
auth_handler = urllib2.HTTPBasicAuthHandler()
auth_handler.add_password('realm', 'host', 'username', 'password')
opener = urllib2.build_opener(auth_handler)
# ...and install it globally so it can be used with urlopen.
urllib2.install_opener(opener)
urllib2.urlopen('http://www.example.com/login.html')

#2

yes

but in this case.. what would the values of 'realm' and 'host' be?
auth_handler.add_password('realm', 'host', 'username', 'password')

i assume host would be the website ip where login is to be done. but what about realm? shouldnt that be obtained from the server?

Thank You

Prashanth
Australia Forum Administrator #3
Quote:

I want to do a project which calculates the broadband usage for a particular ISP


This is bit off-topic for this forum which is basically about clients and servers for MUD games (multi-user dungeons). If someone wants to answer, fine, but otherwise I suggest going to a general Python or programming forum.

I googled for "add_password" and got 791 matches, so perhaps some of those could help you?