# -*- encoding:utf-8 -*-
class transCookie:
def __init__(self, cookie):
self.cookie = cookie
def stringToDict(self):
'''
将从浏览器上Copy来的cookie字符串转化为Scrapy能使用的Dict
:return:
'''
itemDict = {}
items = self.cookie.split(';')
for item in items:
key = item.split('=')[0].replace(' ', '')
value = item.split('=')[1]
itemDict[key] = value
return itemDict
if __name__ == "__main__":
cookie = "_T_WM=13ef29cb9516473f9475573ef297661d; SUHB=00xpM5hOztvM2L; SCF=AlONH2rD_LBzr6GVUE0s6krxj764DL92M7-eHaQKXY4CZA-R8gCEb5Y_2hC0fP3arrv_er_04MUSTGNyRS_URlQ.; SUBP=0033WrSXqPxfM725Ws9jqgMF55529P9D9WWax-a_krO4TiigaOBe-war5JpX5KzhUgL.Fo-R1hq7S0.XSh-2dJLoI0qLxKBLB.qL1KMLxKBLBonL12BLxK-L12qLB-qLxKnL1h5L1K5LxKML1-2L1hBLxKqL1hnL1K2t; SUB=_2A250nfa7DeRhGeNG41QR9yfIzzmIHXVUYZrzrDV6PUJbkdAKLRejkW17O67wHke_9owbb1RnlkXwL7k0Wg..; _TTT_USER_CONFIG_H5=%7B%22ShowMblogPic%22%3A1%2C%22ShowUserInfo%22%3A1%2C%22MBlogPageSize%22%3A10%2C%22ShowPortrait%22%3A1%2C%22CssType%22%3A0%2C%22Lang%22%3A1%7D; browser=d2VpYm9mYXhpYW4%3D; h5_deviceID=aab2130416b809226bb9f86d47550d9f; BDTUJIAID=ed205fa2a7ba58d68ac1f8e6a9f3f8a8; H5_INDEX=2; H5_INDEX_TITLE=%E8%89%BE%E8%BF%AA%E6%88%98%E7%8B%BC; SSOLoginState=1503233771; M_WEIBOCN_PARAMS=featurecode%3D20000320%26luicode%3D10000011%26lfid%3D1076031191220232"
trans = transCookie(cookie)
print trans.stringToDict()