|  | @@ -7,8 +7,10 @@
 | 
	
		
			
				|  |  |  # @contact: renyupeng@c-top.com.cn
 | 
	
		
			
				|  |  |  # @Tel 1501435553
 | 
	
		
			
				|  |  |  import json
 | 
	
		
			
				|  |  | +import random
 | 
	
		
			
				|  |  |  import time
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import redis
 | 
	
		
			
				|  |  |  import requests
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  from utils.cookie_update import cookie_update
 | 
	
	
		
			
				|  | @@ -22,47 +24,53 @@ class SpiderPromoterHeader:
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @staticmethod
 | 
	
		
			
				|  |  |      def GetPromoterInfo(promoter_id):
 | 
	
		
			
				|  |  | +        r = redis.Redis(host='192.168.0.193', password='hcst@2022', port=6379, db=0)
 | 
	
		
			
				|  |  |          listItem = []
 | 
	
		
			
				|  |  |          url = 'https://cps.kwaixiaodian.com/distribute/pc/seller/promoter/info?promoterId={promoterId}&type=1'.format(
 | 
	
		
			
				|  |  |              promoterId=promoter_id)
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        cookie = cookie_update.get_cookie_handler()[0]
 | 
	
		
			
				|  |  | -        phone_num = cookie_update.get_cookie_handler()[1]
 | 
	
		
			
				|  |  | +        if r.zcard('kuaishou_shop_click_token') == 0:
 | 
	
		
			
				|  |  | +            cookie_update.get_click_coookie_to_redis()
 | 
	
		
			
				|  |  | +        else:
 | 
	
		
			
				|  |  | +            random_member = r.zrange('kuaishou_shop_click_token', 0, -1, withscores=True)
 | 
	
		
			
				|  |  | +            random_item = random.choice(random_member)
 | 
	
		
			
				|  |  | +            cookie = random_item[0].decode('utf-8')
 | 
	
		
			
				|  |  | +            phone_num = int(random_item[1])
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        headers = {'User-Agent': 'Mozilla/5.0',
 | 
	
		
			
				|  |  | -                   'Cookie': cookie}
 | 
	
		
			
				|  |  | +            headers = {'User-Agent': 'Mozilla/5.0',
 | 
	
		
			
				|  |  | +                       'Cookie': cookie}
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        try:
 | 
	
		
			
				|  |  | -            rep = requests.get(url=url, headers=headers)
 | 
	
		
			
				|  |  | -            print(rep.text, '-----rep.txt---------')
 | 
	
		
			
				|  |  | -            # if json.loads(rep.text)["result"] != 1 and json.loads(rep.text)["result"] != 100110000:
 | 
	
		
			
				|  |  | -            #     cookie_update.update_temporary_cookie_handler(phone_num)
 | 
	
		
			
				|  |  | -            #     retry_cookie = cookie_update.get_cookie_handler()[0]
 | 
	
		
			
				|  |  | -            #     headers = {'User-Agent': 'Mozilla/5.0',
 | 
	
		
			
				|  |  | -            #                'Cookie': retry_cookie}
 | 
	
		
			
				|  |  | -            #     rep = requests.get(url=url, headers=headers)
 | 
	
		
			
				|  |  | -            #     data = json.loads(rep.text)["data"]
 | 
	
		
			
				|  |  | -            #     item = {"fans": data["fanNum"], "handurl": data["promoterHeadImgUrl"],
 | 
	
		
			
				|  |  | -            #             "promoter_name": data["promoterNickName"],
 | 
	
		
			
				|  |  | -            #             "promoter_id": promoter_id}
 | 
	
		
			
				|  |  | -            #     listItem.append(item)
 | 
	
		
			
				|  |  | -            #     return listItem
 | 
	
		
			
				|  |  | -            # elif json.loads(rep.text)["result"] == 100110000:
 | 
	
		
			
				|  |  | -            #     cookie_update.update_cookie_handler(phone_num)
 | 
	
		
			
				|  |  | -            #     return
 | 
	
		
			
				|  |  | -            if json.loads(rep.text)["result"] == 1:
 | 
	
		
			
				|  |  | -                data = json.loads(rep.text)["data"]
 | 
	
		
			
				|  |  | -                print(data)
 | 
	
		
			
				|  |  | -                item = {"fans": data["fanNum"], "handurl": data["promoterHeadImgUrl"],
 | 
	
		
			
				|  |  | -                        "promoter_name": data["promoterNickName"],
 | 
	
		
			
				|  |  | -                        "promoter_id": promoter_id}
 | 
	
		
			
				|  |  | -                listItem.append(item)
 | 
	
		
			
				|  |  | -                return listItem
 | 
	
		
			
				|  |  | -            else:
 | 
	
		
			
				|  |  | -                return
 | 
	
		
			
				|  |  | -        except Exception as e:
 | 
	
		
			
				|  |  | -            SendFeiShuMsg.send_robot_msg(
 | 
	
		
			
				|  |  | -                'GetPromoterInfo {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoter_id, e=e))
 | 
	
		
			
				|  |  | +            try:
 | 
	
		
			
				|  |  | +                rep = requests.get(url=url, headers=headers)
 | 
	
		
			
				|  |  | +                print(rep.text, '-----rep.txt---------')
 | 
	
		
			
				|  |  | +                # if json.loads(rep.text)["result"] != 1 and json.loads(rep.text)["result"] != 100110000:
 | 
	
		
			
				|  |  | +                #     cookie_update.update_temporary_cookie_handler(phone_num)
 | 
	
		
			
				|  |  | +                #     retry_cookie = cookie_update.get_cookie_handler()[0]
 | 
	
		
			
				|  |  | +                #     headers = {'User-Agent': 'Mozilla/5.0',
 | 
	
		
			
				|  |  | +                #                'Cookie': retry_cookie}
 | 
	
		
			
				|  |  | +                #     rep = requests.get(url=url, headers=headers)
 | 
	
		
			
				|  |  | +                #     data = json.loads(rep.text)["data"]
 | 
	
		
			
				|  |  | +                #     item = {"fans": data["fanNum"], "handurl": data["promoterHeadImgUrl"],
 | 
	
		
			
				|  |  | +                #             "promoter_name": data["promoterNickName"],
 | 
	
		
			
				|  |  | +                #             "promoter_id": promoter_id}
 | 
	
		
			
				|  |  | +                #     listItem.append(item)
 | 
	
		
			
				|  |  | +                #     return listItem
 | 
	
		
			
				|  |  | +                # elif json.loads(rep.text)["result"] == 100110000:
 | 
	
		
			
				|  |  | +                #     cookie_update.update_cookie_handler(phone_num)
 | 
	
		
			
				|  |  | +                #     return
 | 
	
		
			
				|  |  | +                if json.loads(rep.text)["result"] == 1:
 | 
	
		
			
				|  |  | +                    data = json.loads(rep.text)["data"]
 | 
	
		
			
				|  |  | +                    print(data)
 | 
	
		
			
				|  |  | +                    item = {"fans": data["fanNum"], "handurl": data["promoterHeadImgUrl"],
 | 
	
		
			
				|  |  | +                            "promoter_name": data["promoterNickName"],
 | 
	
		
			
				|  |  | +                            "promoter_id": promoter_id}
 | 
	
		
			
				|  |  | +                    listItem.append(item)
 | 
	
		
			
				|  |  | +                    return listItem
 | 
	
		
			
				|  |  | +                else:
 | 
	
		
			
				|  |  | +                    return
 | 
	
		
			
				|  |  | +            except Exception as e:
 | 
	
		
			
				|  |  | +                SendFeiShuMsg.send_robot_msg(
 | 
	
		
			
				|  |  | +                    'GetPromoterInfo {promoterId}请求错误请检查cookie{e}'.format(promoterId=promoter_id, e=e))
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      def GetPromoterID(self):
 | 
	
		
			
				|  |  |          try:
 |