码迷,mamicode.com
首页 > 其他好文 > 详细

Collections之OrderedDict()

时间:2021-05-24 00:24:16      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:apple   gen   arm   insecure   page   change   use   flat   ret   

def str_to_dic(headerStr, stripIsNotvalid=None):
    dict = collections.OrderedDict() #对字典对象中元素的排序。
    if headerStr.strip():
        for headItem in headerStr.split("\n"):
            parm = headItem.split(":")
            if stripIsNotvalid:
                dict[parm[0]] = headItem[(headItem.index(parm[0]) + parm[0].__len__() + 1):].lstrip()
            else:
                dict[parm[0]] = headItem[(headItem.index(parm[0]) + parm[0].__len__() + 1):].strip()
    print(dict)
    return dict

pageHeader = str_to_dic(
    "Host: ahbbzy.ts.sifayun.com\n" +
    "Connection: keep-alive\n" +
    "Upgrade-Insecure-Requests: 1\n" +
    "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36\n" +
    "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9\n" +
    "Accept-Encoding: gzip, deflate\n" +
    "Accept-Language: zh-CN,zh;q=0.9")

 

Collections之OrderedDict()

标签:apple   gen   arm   insecure   page   change   use   flat   ret   

原文地址:https://www.cnblogs.com/Eliphaz/p/14738374.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!