import http.cookiejar,urllib.request
# cookie=http.cookiejar.CookieJar()
# handle=urllib.request.HTTPCookieProcessor(cookie)
# opener=urllib.request.build_opener(handle)
# respose=opener.open('http://www.baidu.com')
# for item in cookie:
# print(item.name+"="+item.value)
filename='cookies.txt'
cookie=http.cookiejar.MozillaCookieJar(filename)
handle=urllib.request.HTTPCookieProcessor(cookie)
opener=urllib.request.build_opener(handle)
respose=opener.open('http://www.baidu.com')
cookie.save(ignore_discard=True,ignore_expires=True)