zoukankan      html  css  js  c++  java
  • python 一行代码字符串转字典方法

    b = 'bid=Qzw9cKnyESM; ll="108288"; __yadk_uid=4YChvgeANLBEh4iV00n1tc0HQ8zpmSl1; __utmc=30149280; __utmc=223695111; _vwo_uuid_v2=D8099FF3ECFE384A3F35BFA190C05A5EE|91f795432cda34bbc17ba6265fb33177; ps=y; dbcl2="169126613:FUpqH/CNWB8"; ck=pyZ7; ap=1; push_noty_num=0; push_doumail_num=0; __utmz=30149280.1520490941.8.7.utmcsr=accounts.douban.com|utmccn=(referral)|utmcmd=referral|utmcct=/login; __utmv=30149280.16912; __utmz=223695111.1520492304.6.4.utmcsr=douban.com|utmccn=(referral)|utmcmd=referral|utmcct=/search; ct=y; __utma=30149280.1712477244.1514880643.1520490941.1520496097.9; __utmb=30149280.0.10.1520496097; __utma=223695111.1169484511.1516955420.1520492304.1520496097.7; __utmb=223695111.0.10.1520496097; _pk_ref.100001.4cf6=%5B%22%22%2C%22%22%2C1520496097%2C%22https%3A%2F%2Fwww.douban.com%2Fsearch%3Fsource%3Dsuggest%26q%3D%25E5%2589%258D%25E4%25BB%25BB%22%5D; _pk_ses.100001.4cf6=*; _pk_id.100001.4cf6=21a4461bbb469631.1516955420.7.1520496674.1520492685'
    cookie = {}
    for line in b.split(';'):
    key, value = line.split('=', 1)
    cookie[key] = value
    print(cookie)

    cookies = dict([l.split("=", 1) for l in b.split("; ")])
    print(cookies)
    cookie_dict = dict((line.split('=',1) for line in b.strip().split(";")))
    print(cookie_dict)
    》》》》《结果》
    {'bid': 'Qzw9cKnyESM', ' ll': '"108288"', ' __yadk_uid': '4YChvgeANLBEh4iV00n1tc0HQ8zpmSl1', ' __utmc': '223695111', ' _vwo_uuid_v2': 'D8099FF3ECFE384A3F35BFA190C05A5EE|91f795432cda34bbc17ba6265fb33177', ' ps': 'y', ' dbcl2': '"169126613:FUpqH/CNWB8"', ' ck': 'pyZ7', ' ap': '1', ' push_noty_num': '0', ' push_doumail_num': '0', ' __utmz': '223695111.1520492304.6.4.utmcsr=douban.com|utmccn=(referral)|utmcmd=referral|utmcct=/search', ' __utmv': '30149280.16912', ' ct': 'y', ' __utma': '223695111.1169484511.1516955420.1520492304.1520496097.7', ' __utmb': '223695111.0.10.1520496097', ' _pk_ref.100001.4cf6': '%5B%22%22%2C%22%22%2C1520496097%2C%22https%3A%2F%2Fwww.douban.com%2Fsearch%3Fsource%3Dsuggest%26q%3D%25E5%2589%258D%25E4%25BB%25BB%22%5D', ' _pk_ses.100001.4cf6': '', ' _pk_id.100001.4cf6': '21a4461bbb469631.1516955420.7.1520496674.1520492685'}
    {'bid': 'Qzw9cKnyESM', 'll': '"108288"', '__yadk_uid': '4YChvgeANLBEh4iV00n1tc0HQ8zpmSl1', '__utmc': '223695111', '_vwo_uuid_v2': 'D8099FF3ECFE384A3F35BFA190C05A5EE|91f795432cda34bbc17ba6265fb33177', 'ps': 'y', 'dbcl2': '"169126613:FUpqH/CNWB8"', 'ck': 'pyZ7', 'ap': '1', 'push_noty_num': '0', 'push_doumail_num': '0', '__utmz': '223695111.1520492304.6.4.utmcsr=douban.com|utmccn=(referral)|utmcmd=referral|utmcct=/search', '__utmv': '30149280.16912', 'ct': 'y', '__utma': '223695111.1169484511.1516955420.1520492304.1520496097.7', '__utmb': '223695111.0.10.1520496097', '_pk_ref.100001.4cf6': '%5B%22%22%2C%22%22%2C1520496097%2C%22https%3A%2F%2Fwww.douban.com%2Fsearch%3Fsource%3Dsuggest%26q%3D%25E5%2589%258D%25E4%25BB%25BB%22%5D', '_pk_ses.100001.4cf6': '
    ', '_pk_id.100001.4cf6': '21a4461bbb469631.1516955420.7.1520496674.1520492685'}
    {'bid': 'Qzw9cKnyESM', ' ll': '"108288"', ' __yadk_uid': '4YChvgeANLBEh4iV00n1tc0HQ8zpmSl1', ' __utmc': '223695111', ' _vwo_uuid_v2': 'D8099FF3ECFE384A3F35BFA190C05A5EE|91f795432cda34bbc17ba6265fb33177', ' ps': 'y', ' dbcl2': '"169126613:FUpqH/CNWB8"', ' ck': 'pyZ7', ' ap': '1', ' push_noty_num': '0', ' push_doumail_num': '0', ' __utmz': '223695111.1520492304.6.4.utmcsr=douban.com|utmccn=(referral)|utmcmd=referral|utmcct=/search', ' __utmv': '30149280.16912', ' ct': 'y', ' __utma': '223695111.1169484511.1516955420.1520492304.1520496097.7', ' __utmb': '223695111.0.10.1520496097', ' _pk_ref.100001.4cf6': '%5B%22%22%2C%22%22%2C1520496097%2C%22https%3A%2F%2Fwww.douban.com%2Fsearch%3Fsource%3Dsuggest%26q%3D%25E5%2589%258D%25E4%25BB%25BB%22%5D', ' _pk_ses.100001.4cf6': '*', ' _pk_id.100001.4cf6': '21a4461bbb469631.1516955420.7.1520496674.1520492685'}

    《《《

  • 相关阅读:
    IIS7.5 webapi 不支持 Delete、Put 解决方法
    pip 安装 MySQL-python 失败
    Windows 下针对python脚本做一个简单的进程保护
    Python 多线程 Condition 的使用
    Python 无限循环
    Window nginx+tomcat+https部署方案 支持ios9
    Window Redis分布式部署方案 java
    Struts2注解 特别注意
    PermGen space Eclipse 终极解决方案
    特别备注一下一个缓存加载的问题,百度上还搜不出来,在一个老外的网站上看到的
  • 原文地址:https://www.cnblogs.com/duanlinxiao/p/9845707.html
Copyright © 2011-2022 走看看