Advertisement
wandrake

Untitled

Feb 27th, 2012
3,255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PyCon 0.93 KB | None | 0 0
  1. #!/usr/bin/env python2.6
  2. # -*- coding: utf-8 -*-
  3.  
  4. import urllib
  5. import urllib2
  6. # build opener with HTTPCookieProcessor
  7. o = urllib2.build_opener( urllib2.HTTPCookieProcessor() )
  8. urllib2.install_opener( o )
  9.  
  10. # assuming the site expects 'user' and 'pass' as query params
  11. p = urllib.urlencode( { 'username': '', 'password': '', 'provider': 'LDAP UniPi' } )
  12.  
  13.  
  14. # perform login with params
  15. f = o.open( 'https://auth1.unipi.it/auth/perfigo_cm_validate.jsp',  p )
  16. data = f.read()
  17. e.close()
  18. f.close()
  19.  
  20. p = urllib.urlencode( { 'username': '', 'password': '', 'provider': 'LDAP UniPi', 'remove_old': '1' } )
  21.  
  22. # perform login with params
  23. f = o.open( 'https://auth1.unipi.it/auth/perfigo_cm_validate.jsp',  p )
  24. data = f.read()
  25. e.close()
  26. f.close()
  27.  
  28. # second request should automatically pass back any
  29. # cookies received during login... thanks to the HTTPCookieProcessor
  30. f = o.open( 'http://www.google.it' )
  31. data = f.read()
  32. f.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement