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

等号对2字典

时间:2018-05-01 23:33:47      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:else   arch   gecko   app   lse   lan   line   text   __name__   

def denghao2maohao(cookie_str):
    # 截断数据对
    list1 = cookie_str.split("; ")
    # print(list1)
    # 初始化字典
    cookie_dict_str = {}
    for item in list1:
        list2 = item.split("=")
        print(list2)
        cookie_dict_str[list2[0]] = list2[1]


if __name__ == ‘__main__‘:
    # 原始等号对数据
    cookie_str = "ss_lang=cs; product=WGSN; ss_udid=0ed9a26e6dd6bb892c796cda69bca4a3; PHPSESSID=ci56j78njjgdqde5tjepslaah5; exclusionChecked=True; ss_token=f77dcbc5a65f43977e02b61e9d6ff947; trwv.uid=stylesight-1525165098107-fd45157e%3A2; trwsa.sid=stylesight-1525177471085-3d01fa38%3A2; _ga=GA1.2.1824486173.1525165097; _gid=GA1.2.1794994253.1525165097; cp_browStat=Logged In; cp_UserID=-1; cp_hybridBrowStat=Logged In; cp_SubStat=Subscriber"
    # print(cookie_str)
    cookie_dict_str=denghao2maohao(cookie_str)
    print(cookie_dict_str)




def maohao2yinhao(maohao_str):
    list1 = maohao_str.strip().splitlines()
    maohao_str_dict = {}
    for item in list1:
        if item.startswith(":"):
            print(item)
            list2 = item.split(":", 2)  # 按照分号截断2次
            print(list2)
            maohao_str_dict[":" + list2[1]] = list2[2]
        else:
            print(item)
            list2 = item.split(":", 1)  # 按照分号截断1次
            maohao_str_dict[list2[0]] = list2[1]
    return maohao_str_dict


if __name__ == ‘__main__‘:
    #     冒号填引号
    maohao_str = """
    :authority:www.wgsnchina.cn
    :method:POST
    :path:/api/cherry/search/query
    :scheme:https
    accept:application/json, text/plain, */*
    accept-encoding:gzip, deflate, br
    accept-language:zh-CN,zh;q=0.9
    content-length:149
    content-type:application/json;charset=UTF-8
    cookie:ss_lang=cs; product=WGSN; ss_udid=0ed9a26e6dd6bb892c796cda69bca4a3; PHPSESSID=ci56j78njjgdqde5tjepslaah5; exclusionChecked=True; ss_token=f77dcbc5a65f43977e02b61e9d6ff947; _gat_UA-1004012-2=1; cp_SubStat=Subscriber; cp_browStat=Logged In; cp_UserID=-1; cp_hybridBrowStat=Logged In; _dc_gtm_UA-1004012-2=1; _ga=GA1.2.1824486173.1525165097; _gid=GA1.2.1794994253.1525165097; trwv.uid=stylesight-1525165098107-fd45157e%3A3; trwsa.sid=stylesight-1525179968287-e61a7bc2%3A2
    origin:https://www.wgsnchina.cn
    referer:https://www.wgsnchina.cn/library/results/ab745207e8ed3dcfa16b4814748beead
    user-agent:Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.89 Safari/537.36


    """
    maohao_str_dict = maohao2yinhao(maohao_str)
    print(maohao_str_dict)

  

等号对2字典

标签:else   arch   gecko   app   lse   lan   line   text   __name__   

原文地址:https://www.cnblogs.com/andy9468/p/8977406.html

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