Skip to content

Instantly share code, notes, and snippets.

@bngsudheer
Created October 19, 2010 19:40
Show Gist options
  • Save bngsudheer/634927 to your computer and use it in GitHub Desktop.
Save bngsudheer/634927 to your computer and use it in GitHub Desktop.
Cookiejar with urllib2 example
import urllib2
import urllib
from cookielib import CookieJar
cj = CookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
values = {'username': 'admin', 'password': 'password'}
data = urllib.urlencode(values)
response = opener.open("http://toscrape.techchorus.net/do_login.php", data)
print response.read()
response2 = opener.open('http://toscrape.techchorus.net/only_authenticated.php')
print response2.read()
#Visit http://techchorus.net/using-cookie-jar-urllib2 for explanation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment