import os
import urllib2
import cookielib
from urllib2 import urlopen, Request
cookieFile = "cookies.dat"
testURL = 'http://maps.google.com/'
cJar = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cJar))
urllib2.install_opener(opener)
r = Request(testURL)
h = urlopen(r)
print h.info()
for ind, cookie in enumerate(cJar):
print "%d - %s" % (ind, cookie)
cJar.save(cookieFile)
|