""" Author renyupeng coding=utf-8 @Time : 2023/2/7 2:34 下午 @Site : @File : PromoterInfoSpider.py @Software: PyCharm @contact: renyupeng@c-top.com.cn @Tel 1501435553 """ import json import requests from utils.mysql_helper import insert from utils.mysql_utils import MysqlUtils from utils.send_feishu_msg import SendFeiShuMsg class PromoterInfoSpider: def __init__(self): self.conn = MysqlUtils() @staticmethod def PromoterInfoSpiderHandler(promoterId, cookie): url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format( promoterId=promoterId) headers = {'User-Agent': 'Mozilla/5.0', 'Cookie': cookie} try: rep = requests.get(url=url, headers=headers) table_name = 'kwai_promoter_info' data = json.loads(rep.text)["data"] print(data,'----data--') promoter_info_item = {"addressinfo": json.dumps(data["addressInfo"]), "alreadylookcontact": data["alreadyLookContact"], "existEffectInvestment": data["existEffectInvestment"], "fanNum": data["fanNum"], "firstLookContact": data["firstLookContact"], "hotSaleBrandInfo": json.dumps(data["hotSaleBrandInfo"]), "hotSaleChannelInfo": json.dumps(data["hotSaleChannelInfo"]), "inviteChannelInfo": json.dumps(data["inviteChannelInfo"]), "inviteCommissionRate": data["inviteCommissionRate"], "isActivePromoter": data["isActivePromoter"], "isAllowedInvite": data["isAllowedInvite"], "lookNumber": data["lookNumber"], "phone": data["phone"], "promoteBaseInfo": json.dumps(data["promoteBaseInfo"]), "promoterHeadImgUrl": data["promoterHeadImgUrl"], "promoterId": data["promoterId"], "promoterInviteFee": data["promoterInviteFee"], "promoterNickName": data["promoterNickName"], "showContact": data["showContact"], "showContactReason": data["showContactReason"], "updateTime": data["updateTime"], "userSex": data["userSex"], "weChat": data["weChat"]} insert(table_name=table_name, item=promoter_info_item) base_table_name = 'kwai_promoter_base_info' promoter_base_info_item = {"addressinfo": (json.dumps(data["addressInfo"]),), "hotSaleBrandInfo": (json.dumps(data["hotSaleBrandInfo"]),), "hotSaleChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),), "inviteChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),), "inviteCommissionRate": data["inviteCommissionRate"], "avgLiveVisitorCount": data["promoteBaseInfo"]["avgLiveVisitorCount"], "avgLiveVisitorGmv": data["promoteBaseInfo"]["avgLiveVisitorGmv"], "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"], "avgVideoViewers": data["promoteBaseInfo"]["avgVideoViewers"], "coopStoresNum": data["promoteBaseInfo"]["coopStoresNum"], "fansNum": data["promoteBaseInfo"]["fansNum"], "liveExperienceMSGap": data["promoteBaseInfo"]["liveExperienceMSGap"], "liveStreamCount": data["promoteBaseInfo"]["liveStreamCount"], "liveStreamGMV": data["promoteBaseInfo"]["liveStreamGMV"], "liveStreamGPM": data["promoteBaseInfo"]["liveStreamGPM"], "liveStreamVisitorCount": data["promoteBaseInfo"]["liveStreamVisitorCount"], "promoteAvgCustomerPrice": data["promoteBaseInfo"]["promoteAvgCustomerPrice"], "promoteAvgPrice": data["promoteBaseInfo"]["promoteAvgPrice"], "promoteLiveCount": data["promoteBaseInfo"]["promoteLiveCount"], "promoteSaleVolume": data["promoteBaseInfo"]["promoteSaleVolume"], "promoteStartTime": data["promoteBaseInfo"]["promoteStartTime"], "promotedProductsNum": data["promoteBaseInfo"]["promotedProductsNum"], "promoterId": data["promoterId"], "totalSale": data["promoteBaseInfo"]["totalSale"], "videoGPM": data["promoteBaseInfo"]["videoGPM"], "videoNum": data["promoteBaseInfo"]["videoNum"], "videoSales": data["promoteBaseInfo"]["videoSales"], "videoViews": data["promoteBaseInfo"]["videoViews"], "promoterInviteFee": data["promoterInviteFee"], "promoterNickName": data["promoterNickName"], "showContact": data["showContact"], "showContactReason": data["showContactReason"], "updateTime": data["updateTime"], "userSex": data["userSex"], "weChat": data["userSex"]} insert(table_name=base_table_name, item=promoter_base_info_item) except Exception as e: SendFeiShuMsg.send_robot_msg( 'PromoterInfoSpider {promoterId}请求错误请检查cookie'.format(promoterId=promoterId, e=e)) if __name__ == '__main__': cookie='cross-site-cookie=bar; did=web_edb485f1d19c33f7478202d941312a87163c; soft_did=1619580708547; sid=kuaishou.shop.b; pluto-ratio-/=42165_10@-1; userId=562684945; kuaishou.shop.b_st=ChJrdWFpc2hvdS5zaG9wLmIuc3QSoAGH-PMeJttzsGoPta-mGv6NAfeehWL_hxIIixRF_bcL61iYiznPh2DjWRvib_K5lf-bPbwanblk8ogYy88UAHm4J-QO2y-4aTnmihmw0P5tqc9l7cpPujXPW204YAgpoWBSJhhMRmBurF8a41FzAHwjCHq-GLBsdK3sR5THN_1KZPEVR8ZxJlHtnWOuQZXdducvFuF4kfcaPxglUmetPwzQGhJx70cBBaGVtEpnSlNxog9ZoqoiIKSW7r-AocDZt6H5zesHoOJJqZt34pQZX9tLPYNH_hEUKAUwAQ; kuaishou.shop.b_ph=032e0260c3180a0fc24b4ea1a14a0f99390d' id = 3138455554 PromoterInfoSpider.PromoterInfoSpiderHandler(id,cookie)