#!/usr/bin/env python2.6 # -*- coding: utf-8 -*- import urllib import urllib2 # build opener with HTTPCookieProcessor o = urllib2.build_opener( urllib2.HTTPCookieProcessor() ) urllib2.install_opener( o ) # assuming the site expects 'user' and 'pass' as query params p = urllib.urlencode( { 'username': '', 'password': '', 'provider': 'LDAP UniPi' } ) # perform login with params f = o.open( 'https://auth1.unipi.it/auth/perfigo_cm_validate.jsp', p ) data = f.read() e.close() f.close() p = urllib.urlencode( { 'username': '', 'password': '', 'provider': 'LDAP UniPi', 'remove_old': '1' } ) # perform login with params f = o.open( 'https://auth1.unipi.it/auth/perfigo_cm_validate.jsp', p ) data = f.read() e.close() f.close() # second request should automatically pass back any # cookies received during login... thanks to the HTTPCookieProcessor f = o.open( 'http://www.google.it' ) data = f.read() f.close()