In order to work with cookies with urllib, we can use the HTTPCookieProcessor handler from the urllib.request package:
>>> import urllib>>> cookie_processor = urllib.request.HTTPCookieProcessor()
If we want to access these cookies or be able to send our own cookies, we can pass a CookieJar object of the cookielib module as a parameter to the HTTPCookieProcessor initializer.
To read the cookies that the server sends us, just create an iterable object of the CookieJar class from the http.cookiejar package. This will automatically extract the cookies from the responses that we receive and then store them in our cookie jar:
>>> from http.cookiejar import CookieJar>>> cookie_jar = CookieJar()>>> cookie_processor = ...