Guest User

Untitled

a guest
Jan 16th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. def cookies2dict(cookie):
  2. """从浏览器或者request headers中拿到cookie字符串,提取为字典格式的cookies"""
  3. cookies = dict([l.strip().split("=", 1) for l in cookie.split(";") if l])
  4. return cookies
  5.  
  6. if __name__ == "__main__":
  7. cookie = "__trackId=151539619154927; Hm_lvt_5a727f1b4acc5725516637e03b07d3d2=1514513175,1514945507; _ga=GA1.2.814216675.1514513179; __city=suzhou; Hm_lpvt_5a727f1b4acc5725516637e03b07d3d2=1514972628; __s=40lhpg0m0r2sm2541lvar3m9p3;"
  8. print cookies2dict(cookie)
Add Comment
Please, Sign In to add comment