if os.path.isFile('./cookies.txt'):
    cj = pickle.load(open('./cookies.txt', 'rb'))
else:
    cj = cookielib.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
r = opener.open('http://example.com/')
Cookies with urllib2 and PyWebKitGtk