code_junkie

Cookie Problem in Python

Nov 13th, 2011
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. import urllib
  2. import urllib2
  3. from cookielib import CookieJar
  4. #make a cookie and redirect handlers
  5. cookies = CookieJar()
  6. cookie_handler= urllib2.HTTPCookieProcessor(cookies)
  7. redirect_handler= urllib2.HTTPRedirectHandler()
  8.  
  9. opener = urllib2.build_opener(redirect_handler,cookie_handler)#make opener w/ handlers
  10.  
  11. #build the url
  12. login_info = {'username':USER,'password':PASS}#USER and PASS are defined
  13. data = urllib.urlencode(login_info)
  14.  
  15. req = urllib2.Request("http://www.hulu.com/account/authenticate",data)#make the request
  16. test = opener.open(req) #open the page
  17. print test.read() #print html results
  18.  
  19. Login.onError("Please 74a href="/support/login_faq#cant_login"76enable cookies74/a76 and try again.");
Add Comment
Please, Sign In to add comment