python3使用urllib获取set-cookies

#!/usr/bin/env python  
# encoding: utf-8  
import urllib.request
from collections import defaultdict
response=urllib.request.urlopen("https://twitter.com/login")
headerstr=response.getheaders()
d = defaultdict(list)
for k, v in headerstr:
    if "set-cookie" in k:
        d[k].append(v)
print(d.items())

  上面只是为了做一个 列表 元组转字典的练习,下面才是开始

#!/usr/bin/env python  
# encoding: utf-8  
import urllib.request
from collections import defaultdict
response=urllib.request.urlopen("https://twitter.com/login")
headerstr=response.getheader("set-cookie")
print(headerstr)

  

posted @ 2018-05-10 09:01  公众号python学习开发  阅读(1071)  评论(0编辑  收藏  举报