python3使用urllib获取set-cookies

1
2
3
4
5
6
7
8
9
10
11
#!/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())

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

1
2
3
4
5
6
7
#!/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)

  

本文作者:公众号python学习开发

本文链接:https://www.cnblogs.com/c-x-a/p/9017885.html

版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。

posted @   公众号python学习开发  阅读(1087)  评论(0编辑  收藏  举报
历史上的今天:
2017-05-10 python的map/reduce区别
2016-05-10 nodejs的 new String
点击右上角即可分享
微信分享提示
评论
收藏
关注
推荐
深色
回顶
收起