cookies提取
程序员文章站
2022-05-11 22:59:10
...
从浏览器或者request headers中拿到cookie字符串,提取为字典格式的cookies
def result_cookies(cookie):
cookies = dict([l.split("=", 1) for l in cookie.split("; ")])
print(cookies)
if __name__ == "__main__":
cookie = "acw_tc=1bdd549715452992528884057e4ceb9fe2073000cde22daac8fec5e8e7; QCCSESSID=99qm8tm45mpp2gs1i0h76lu2i5; UM_distinctid=167cb035cac3d4-02da70d47bd961-b781636-1fa400-167cb035cae8ca; _uab_collina=154529925513855047979453; saveFpTip=true; zg_did=%7B%22did%22%3A%20%22167cb03605f173-0f09b2c0059971-b781636-1fa400-167cb036060201%22%7D; hasShow=1; CNZZDATA1254842228=1057596649-1545296191-%7C1545377891; Hm_lvt_3456bee468c83cc63fb5147f119f1075=1545299255,1545375427,1545378719; zg_de1d1a35bfa24ce29bbf2c7eb17e6c4f=%7B%22sid%22%3A%201545375426067%2C%22updated%22%3A%201545381687510%2C%22info%22%3A%201545299255407%2C%22superProperty%22%3A%20%22%7B%7D%22%2C%22platform%22%3A%20%22%7B%7D%22%2C%22utm%22%3A%20%22%7B%7D%22%2C%22referrerDomain%22%3A%20%22www.baidu.com%22%2C%22cuid%22%3A%20%22167c5ee51292c1bf8afddce100cd2be7%22%7D; Hm_lpvt_3456bee468c83cc63fb5147f119f1075=1545381688"
cookies = result_cookies(cookie)