PromoterInfoSpider.py 6.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. """
  2. Author renyupeng
  3. coding=utf-8
  4. @Time : 2023/2/7 2:34 下午
  5. @Site :
  6. @File : PromoterInfoSpider.py
  7. @Software: PyCharm
  8. @contact: renyupeng@c-top.com.cn
  9. @Tel 1501435553
  10. """
  11. import json
  12. import requests
  13. from utils.mysql_helper import insert
  14. from utils.mysql_utils import MysqlUtils
  15. from utils.send_feishu_msg import SendFeiShuMsg
  16. class PromoterInfoSpider:
  17. def __init__(self):
  18. self.conn = MysqlUtils()
  19. @staticmethod
  20. def PromoterInfoSpiderHandler(promoterId, cookie):
  21. url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
  22. promoterId=promoterId)
  23. headers = {'User-Agent': 'Mozilla/5.0',
  24. 'Cookie': cookie}
  25. try:
  26. rep = requests.get(url=url, headers=headers)
  27. table_name = 'kwai_promoter_info'
  28. data = json.loads(rep.text)["data"]
  29. print(data,'----data--')
  30. promoter_info_item = {"addressinfo": json.dumps(data["addressInfo"]),
  31. "alreadylookcontact": data["alreadyLookContact"],
  32. "existEffectInvestment": data["existEffectInvestment"], "fanNum": data["fanNum"],
  33. "firstLookContact": data["firstLookContact"],
  34. "hotSaleBrandInfo": json.dumps(data["hotSaleBrandInfo"]),
  35. "hotSaleChannelInfo": json.dumps(data["hotSaleChannelInfo"]),
  36. "inviteChannelInfo": json.dumps(data["inviteChannelInfo"]),
  37. "inviteCommissionRate": data["inviteCommissionRate"],
  38. "isActivePromoter": data["isActivePromoter"],
  39. "isAllowedInvite": data["isAllowedInvite"], "lookNumber": data["lookNumber"],
  40. "phone": data["phone"], "promoteBaseInfo": json.dumps(data["promoteBaseInfo"]),
  41. "promoterHeadImgUrl": data["promoterHeadImgUrl"], "promoterId": data["promoterId"],
  42. "promoterInviteFee": data["promoterInviteFee"],
  43. "promoterNickName": data["promoterNickName"],
  44. "showContact": data["showContact"], "showContactReason": data["showContactReason"],
  45. "updateTime": data["updateTime"], "userSex": data["userSex"],
  46. "weChat": data["weChat"]}
  47. insert(table_name=table_name, item=promoter_info_item)
  48. base_table_name = 'kwai_promoter_base_info'
  49. promoter_base_info_item = {"addressinfo": (json.dumps(data["addressInfo"]),),
  50. "hotSaleBrandInfo": (json.dumps(data["hotSaleBrandInfo"]),),
  51. "hotSaleChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
  52. "inviteChannelInfo": (json.dumps(data["hotSaleChannelInfo"]),),
  53. "inviteCommissionRate": data["inviteCommissionRate"],
  54. "avgLiveVisitorCount": data["promoteBaseInfo"]["avgLiveVisitorCount"],
  55. "avgLiveVisitorGmv": data["promoteBaseInfo"]["avgLiveVisitorGmv"],
  56. "avgVideoSales": data["promoteBaseInfo"]["avgVideoSales"],
  57. "avgVideoViewers": data["promoteBaseInfo"]["avgVideoViewers"],
  58. "coopStoresNum": data["promoteBaseInfo"]["coopStoresNum"],
  59. "fansNum": data["promoteBaseInfo"]["fansNum"],
  60. "liveExperienceMSGap": data["promoteBaseInfo"]["liveExperienceMSGap"],
  61. "liveStreamCount": data["promoteBaseInfo"]["liveStreamCount"],
  62. "liveStreamGMV": data["promoteBaseInfo"]["liveStreamGMV"],
  63. "liveStreamGPM": data["promoteBaseInfo"]["liveStreamGPM"],
  64. "liveStreamVisitorCount": data["promoteBaseInfo"]["liveStreamVisitorCount"],
  65. "promoteAvgCustomerPrice": data["promoteBaseInfo"]["promoteAvgCustomerPrice"],
  66. "promoteAvgPrice": data["promoteBaseInfo"]["promoteAvgPrice"],
  67. "promoteLiveCount": data["promoteBaseInfo"]["promoteLiveCount"],
  68. "promoteSaleVolume": data["promoteBaseInfo"]["promoteSaleVolume"],
  69. "promoteStartTime": data["promoteBaseInfo"]["promoteStartTime"],
  70. "promotedProductsNum": data["promoteBaseInfo"]["promotedProductsNum"],
  71. "promoterId": data["promoterId"],
  72. "totalSale": data["promoteBaseInfo"]["totalSale"],
  73. "videoGPM": data["promoteBaseInfo"]["videoGPM"],
  74. "videoNum": data["promoteBaseInfo"]["videoNum"],
  75. "videoSales": data["promoteBaseInfo"]["videoSales"],
  76. "videoViews": data["promoteBaseInfo"]["videoViews"],
  77. "promoterInviteFee": data["promoterInviteFee"],
  78. "promoterNickName": data["promoterNickName"],
  79. "showContact": data["showContact"],
  80. "showContactReason": data["showContactReason"],
  81. "updateTime": data["updateTime"],
  82. "userSex": data["userSex"], "weChat": data["userSex"]}
  83. insert(table_name=base_table_name, item=promoter_base_info_item)
  84. except Exception as e:
  85. SendFeiShuMsg.send_robot_msg(
  86. 'PromoterInfoSpider {promoterId}请求错误请检查cookie'.format(promoterId=promoterId, e=e))
  87. if __name__ == '__main__':
  88. 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'
  89. id = 3138455554
  90. PromoterInfoSpider.PromoterInfoSpiderHandler(id,cookie)