SetCookie.py 2.92 KB

import requests
import csv

if __name__ == '__main__':

    # host = "http://yq-redpacket-api.vchangyi.com"
    # domain = '845C3A9F0A69039F72E7C760BCCE9930'  # 企业号“畅移测试T1”

    host = "https://k-boxing-rp-eve-api.vchangyi.com"
    domain = 'A5AA220A0A69039F1E4115437BDC6FE7'

    cookie_list = []
    auth = []
    data = []
    session = []
    accessTag = []
    res = []

    # 读memUid
    # filename1 = 'memUid15000.csv'
    # filename1 = 'dtdev.csv'
    filename1 = 'k-boxing.csv'
    filename2 = 'kb-dev_AUTH.csv'
    filename3 = 'kb-dev_DATA.csv'
    filename4 = 'kb-dev_SESSIONID.csv'
    filename5 = 'kb-dev_accessTag.csv'
    filename6 = 'resourceauth.csv'

    with open(filename1) as f1:
        reader = csv.DictReader(f1)
        memUidList = [row['memUid'] for row in reader]
    f1.close()

    # print(len(memUidList))

    for i in range(len(memUidList)):
        memUid = memUidList[i]
        setCookie_url = host + '/red-packets-business/v1/api/b/' + domain + '/login/test/set-cookie?memUid=' + memUid

        response = requests.get(setCookie_url)
        print(response.json())

        cookie = response.cookies

        cookie_dict = {}
        cookie_str = ''

        for item in cookie:
            cookie_dict[item.name] = item.value
            # cookie_str = cookie_str + item.name + '=' + item.value + ';'
        # print(cookie_dict)
        # auth[len(auth):len(auth)] = cookie_dict['kb_dev_AUTH'].split()
        # data[len(data):len(data)] = cookie_dict['kb_dev_DATA'].split()
        # session[len(session):len(session)] = cookie_dict['kb_dev_SESSIONID'].split()
        # accessTag[len(accessTag):len(accessTag)] = cookie_dict['kb_dev_accessTag'].split()
        # res[len(res):len(res)] = cookie_dict['resourceauth'].split()

        auth[len(auth):len(auth)] = cookie_dict['kboxing_AUTH'].split()
        data[len(data):len(data)] = cookie_dict['kboxing_DATA'].split()
        session[len(session):len(session)] = cookie_dict['kboxing_SESSIONID'].split()
        accessTag[len(accessTag):len(accessTag)] = cookie_dict['kboxing_accessTag'].split()
        res[len(res):len(res)] = cookie_dict['resourceauth'].split()

    with open(filename2, "w", newline='') as f2:
        writer = csv.writer(f2)
        for row in auth:
            writer.writerow([row])
    f2.close()

    with open(filename3, "w", newline='') as f3:
        writer = csv.writer(f3)
        for row in data:
            writer.writerow([row])
    f3.close()

    with open(filename4, "w", newline='') as f4:
        writer = csv.writer(f4)
        for row in session:
            writer.writerow([row])
    f4.close()

    with open(filename5, "w", newline='') as f5:
        writer = csv.writer(f5)
        for row in accessTag:
            writer.writerow([row])
    f5.close()

    with open(filename6, "w", newline='') as f6:
        writer = csv.writer(f6)
        for row in res:
            writer.writerow([row])
    f6.close()