request web with cookies handling


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import cookielib, urllib, urllib2
  2.  
  3. # install an urlopener which handle cookies
  4. cookiejar = cookielib.CookieJar()
  5. opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookiejar))
  6. urllib2.install_opener(opener)
  7.  
  8. request = urllib2.Request("http://google.fr", None, {})
  9. r=urllib2.urlopen(request)
  10.  
  11. for i in cookiejar:
  12. print i

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.