#!/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)