How can I get cookies using urllib2
<p>I used urllib2 to crawl a website, I wanted to get the response cookies after I login. I tried this:</p>

<pre><code>def test_login():
    log_data = {
        'account': my account,
        'password': my pwd
    }
    post_data = urllib.urlencode(log_data)
    cookjar = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookjar))
    headers = {
            'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
            'Accept-Language': 'en-US,en;q=0.5',
            'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0',
            'Host': the web host,
            'Referer': 
        }
    req = urllib2.Request(the login page, post_data, headers=headers)
    content = opener.open(req)
    print cookjar
    for item in cookjar:
        print item, item.value
</code></pre>

<p>I got this:</p>

<pre><code>&lt;cookielib.CookieJar[&lt;Cookie PHPSESSID=aaaaa for the web/&gt;, &lt;Cookie ytkuser=bbbbb for the web&gt;]&gt;
&lt;Cookie PHPSESSID=aaaaa for the web/&gt; aaaaa 
&lt;Cookie ytkuser=bbbbb for .yitiku.cn/&gt; bbbbb
</code></pre>

<p>this is not the format I want, I want to get a dict like this:
{'ytkuser':'','PHPSESSID':''}. How can I translate the data to a dict? Or any other way to get the cookies? Thanks</p>