美文网首页
【Python】header头部文件解析

【Python】header头部文件解析

作者: Natsuka | 来源:发表于2018-08-28 16:54 被阅读24次

提取requests响应中的头部信息:

headers = input('粘贴头部信息:')

def header_format(h):
#   h = input("粘贴头部信息:")
   lst = h.split('\n')

   m=[]
   for i in lst:
       key = i.split(':')[0]
       value1 = i.split(':')[1]
       value = value1.lstrip()
       m.append([str(key),str(value)])
   return(dict(m))
print('头部信息:\n')
print(header_format(headers))
print({'a':'b'})

相关文章

网友评论

      本文标题:【Python】header头部文件解析

      本文链接:https://www.haomeiwen.com/subject/wvjqwftx.html