【python】+操作字符串+从cookie中获取ctoken、Authorization信息

案例1:

从cookie中获取ctoken、Authorization信息

"""
类功能说明:
1、从cookie中获取Authorization信息
2、从cookie中获取ctoken信息
"""


class GetDataByCookie:
    '''从cookie中获取Authorization信息'''

    def getAuthorizationByCookie(cookie):
        # step1 截取“iToken=”之后的所有字符
        authorization1 = cookie[cookie.rfind("iToken="):]
        # step2 以“:”分割截取后的字符串(返回数组),并获取第一个数组的值
        authorization2 = authorization1.split(";")
        authorization3 = authorization2[0]
        # step3 “iToken=”为7个字符,所以从第7个字符开始,一直截取到最后。截取后的字符即为目标字符
        authorization = authorization3[7:]
        print("Authorization:" + authorization)
        return authorization

    '''从cookie中获取ctoken信息'''

    def getCtokenByCookie(cookie):
        # step1 截取“ctoken=”之后的所有字符
        ctoken1 = cookie[cookie.rfind("ctoken="):]
        # step2 以“:”分割截取后的字符串(返回数组),并获取第一个数组的值
        ctoken2 = ctoken1.split(";")
        ctoken3 = ctoken2[0]
        # step3 “ctoken=”为7个字符,所以从第7个字符开始,一直截取到最后。截取后的字符即为目标字符
        ctoken = ctoken3[7:]
        print("ctoken:" + ctoken)
        return ctoken


if __name__ == "__main__":
    cookie = 'SSO_LANG_V2=ZH-CN; SSO_EMPID_HASH_V2=9771d27fb68b637fa0857a66b9016c85; ctoken=bigfish_ctoken_16dj407keg; JSESSIONID=E7879E53DECD0A280062A69A5FAE4434; iToken=eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbkBhbnRmaW4uY29tIiwiaWF0IjoxNTcxMTI2MDQ2LCJleHAiOjE1NzExMjc4NDZ9.8ZzCOyVQKGSoH_0RTGlHXgce560HV1BlfrV3KSWiC0H9b1-QIozPSpgA_4KSQmxd57LQqY4Pq8DAs-s8g20yJQ; userName="admin@antfin.com"'
    getDataByCookie = GetDataByCookie
    getDataByCookie.getAuthorizationByCookie(cookie)
    getDataByCookie.getCtokenByCookie(cookie)

 

posted @ 2019-10-15 17:24  淡怀  阅读(1870)  评论(0编辑  收藏  举报