Browse Source

文件更新

ClownHe 1 year ago
parent
commit
d5ce0341a7
1 changed files with 13 additions and 4 deletions
  1. 13 4
      cppc_python脚本/服务器脚本/demo_窄门数据获取.py

+ 13 - 4
cppc_python脚本/服务器脚本/demo_窄门数据获取.py

@@ -21,7 +21,14 @@ def downLoadShopsInfoByBrandId(brand_id,sessionId,brand_name,date_time):
         url = f'https://fa.kaoputou.com/api/brand/{brand_id}/shops?slug={brand_id}&status=1&page={page}'
         headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 MicroMessenger/7.0.20.1781(0x6700143B) NetType/WIFI MiniProgramEnv/Windows WindowsWechat/WMPF WindowsWechat(0x63090819) XWEB/8531',
                    'sessionId': sessionId}
-        resp = requests.get(url,headers=headers).json()
+        a = 1
+        while a == 1:
+            try:
+                resp = requests.get(url,headers=headers).json()
+                a = 0
+            except:
+                print(page,'失败')
+                time.sleep(10)
         if page == 1:
             try:
                 shopStatus = resp['shopStatus']['open']
@@ -34,6 +41,8 @@ def downLoadShopsInfoByBrandId(brand_id,sessionId,brand_name,date_time):
         print(f'当前正在获取--第{page}页')
         df_out =  df_out + resp['shops']
         time.sleep(random.uniform(3,4))
+        # if page%10 == 0 :
+        #     time.sleep(20)
     df_out = pd.DataFrame(df_out)
     date_list = lambda df_in: [time.strftime('%Y%m%d',time.strptime(i, "%a, %d %b %Y %H:%M:%S %Z")) for i in df_in]
     df_out['openDate'] = date_list(df_out['openDate'])
@@ -42,9 +51,9 @@ def downLoadShopsInfoByBrandId(brand_id,sessionId,brand_name,date_time):
     print(f'总计用时{time_spend}min')
 
 if __name__ == '__main__':
-    brand_id = 36999430
-    brand_name = '江川右'
-    sessionId = 'wx_455c220ae18a1ffc0527eeb13966bf8a'
+    brand_id = 21903627
+    brand_name = '楼兰辛香'
+    sessionId = 'wx_ab1e429c8ef4b99ecda823313d13b810'
     date_time = time.strftime('%Y%m%d%H%M%S')
     downLoadShopsInfoByBrandId(brand_id,sessionId,brand_name,date_time)
     # openDate = 'Wed, 01 Mar 2023 10:00:00 GMT'