[Tutor] Auto login of website

Lloyd Kvam pythontutor at venix.com
Mon Oct 13 09:01:12 EDT 2003


The urllib and urllib2 modules support accessing a website.  The module
documentation for urllib describes how to create your own class to
override functions provided by urllib.  In your case, you want to
override the method:
     prompt_user_passwd
to return a tuple containing your username and password.

import urllib
class MyURLopener(urllib.FancyURLopener):
     def prompt_user_passwd(host,realm):
     #ignore host and realm
     # substitue your id and password
     return ("mulder", "trustNo1")

urllib._urlopener = MyURLopener()

f = urllib.urlopen("http://www.some.com")
print f.read()

This omits cookie issues and other pitfalls.  You may find it easier to
use a program like wget to access URL's that have cookies and passwords
to control access.


Tony Cappellini wrote:

> 
> 
> Would anyone happen to have a small python program (with or without gui) 
> that can
> 
> log a user into a website, at regular intervals ?
> 
> The program would have to take the following as input (can be 
> hard-coded, or on the cmd line)
> 
> 1. the URL of a website (http)
> 2. the user ID
> 3. the user pasword
> 4. click (simulate a keypress or mouse click) on the button to log the 
> user in
> 
> if the user could not be logged in, due to the website being overloaded, 
> then it would do a retry at the next interval (where the interval can be
> supplied by the user, preferably in seconds)
> 
> I've already checked the Python Cookbook, didn't find a match for the 
> keywords I used
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice:	603-443-6155
fax:	801-459-9582




More information about the Tutor mailing list