import ssl
import http.cookiejar
import urllib.request
from urllib.request import ProxyHandler
from urllib.request import HTTPCookieProcessor
# SSL証明書のエラーを無視する設定
ssl._create_default_https_context = ssl._create_unverified_context
cj = http.cookiejar.CookieJar()
target = '127.0.0.1'
port = '8080'
#プロキシー
proxy_handler = ProxyHandler({'http':target + ':' + port,'https':target + ':' + port})
opener = urllib.request.build_opener(HTTPCookieProcessor(cj),proxy_handler)
r = opener.open("https://google.com/")
r = opener.open("https://google.co.jp/")
for cookie in cj:
print('{0:20} : {1}'.format('version',cookie.version))
print('{0:20} : {1}'.format('name',cookie.name))
print('{0:20} : {1}'.format('value',cookie.value))
print('{0:20} : {1}'.format('port',cookie.port))
print('{0:20} : {1}'.format('path',cookie.path))
print('{0:20} : {1}'.format('secure',cookie.secure))
print('{0:20} : {1}'.format('expires',cookie.expires))
print('{0:20} : {1}'.format('discard',cookie.discard))
print('{0:20} : {1}'.format('comment',cookie.comment))
print('{0:20} : {1}'.format('comment_url',cookie.comment_url))
print('{0:20} : {1}'.format('rfc2109',cookie.rfc2109))
print('{0:20} : {1}'.format('port_specified',cookie.port_specified))
print('{0:20} : {1}'.format('domain_specified',cookie.domain_specified))
print('{0:20} : {1}'.format('domain_initial_dot',cookie.domain_initial_dot))
print('{0:20} : {1}'.format('has_nonstandard_attr',cookie.has_nonstandard_attr('secure')))
print('{0:20} : {1}'.format('get_nonstandard_attr',cookie.get_nonstandard_attr('secure')))
print('{0:20} : {1}'.format('set_nonstandard_attr',cookie.set_nonstandard_attr('test',123)))
print('{0:20} : {1}'.format('is_expired',cookie.is_expired()))