zl程序教程

您现在的位置是:首页 >  后端

当前栏目

python3使用urllib获取set-cookies

Python3set 获取 cookies urllib 使用
2023-09-14 09:06:37 时间
#!/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)