用钥匙拿饼干?

2024-04-19 02:25:13 发布

您现在位置:Python中文网/ 问答频道 /正文

在使用Cookielib时,有没有办法按键获取cookie?你知道吗

# Initalize the CookieJar
cookieJar = cookielib.CookieJar()
opener    = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookieJar))

# Visit page, cookies are set here
req       = urllib2.Request("https://example.com")
resp      = opener.open(req)  
csrfToken = getCSRFToken(resp.read())

cookie是在响应中设置的,但是如何通过它的键访问和访问单个cookie?你知道吗

我使用的是python2.7。你知道吗


Tags: thebuildcookieopenerurllib2reqresp按键