Kaynağa Gözat

1、小年糕和祝福圈子增加曝光
2、中青看点请求重试

zhangliang 1 ay önce
ebeveyn
işleme
038069d39b

+ 2 - 3
application/config/config.py

@@ -2,6 +2,5 @@
 crawler_api_domain = 'http://8.217.192.46:8889'
 zhufuquanzi_view_api = crawler_api_domain + '/crawler/zhu_fu_quan_zi/detail_exposure'
 zhufuquanzi_history_api = crawler_api_domain + '/crawler/zhu_fu_quan_zi/detail_history'
-xiaoniangao_view_api = crawler_api_domain + '/crawler/zhu_fu_quan_zi/detail_exposure'
-xiaoniangao_history_api = crawler_api_domain + '/crawler/zhu_fu_quan_zi/detail_history'
-
+xiaoniangao_view_api = crawler_api_domain + '/crawler/xiao_nian_gao_plus/detail_exposure'
+xiaoniangao_history_api = crawler_api_domain + '/crawler/xiao_nian_gao_plus/detail_history'

+ 7 - 2
spider/crawler_author/zhongqingkandian_author.py

@@ -62,6 +62,11 @@ class ZhongQingKanDianAuthor:
         self.LocalLog.info(f"获取到的用户列表:{self.zqkd_user_list} \n 昨天最后扫描的用户ID{self.last_scanned_id}")
         self.session = requests.session()
 
+    def __del__(self):
+        if self.session:
+            self.LocalLog.info("session 被正确关闭")
+            self.session.close()
+
     def send_request(self, path, data):
         """发送带重试机制的API请求"""
         for attempt in range(self.MAX_RETRIES):
@@ -96,8 +101,8 @@ class ZhongQingKanDianAuthor:
             except Exception as e:
                 tb_info = traceback.format_exc()
                 self.LocalLog.error(f"{path}请求异常: {str(e)} \n {tb_info}")
-
-            time.sleep(random.randint(5, 10))
+            if attempt < self.MAX_RETRIES - 1:
+                time.sleep(random.randint(5, 10))
 
         # 所有重试失败,记录错误并返回None
         self.LocalLog.error(f"{path}达到最大重试次数")

+ 8 - 3
spider/crawler_online/zhongqingkandian.py

@@ -57,6 +57,11 @@ class ZhongQingKanDianRecommend:
         self.LocalLog = Local.logger(self.platform, self.mode)
         self.session = requests.session()
 
+    def __del__(self):
+        if self.session:
+            self.LocalLog.info("session 被正确关闭")
+            self.session.close()
+
     def send_request(self, path, data):
         """发送带重试机制的API请求"""
         for attempt in range(self.MAX_RETRIES):
@@ -91,8 +96,8 @@ class ZhongQingKanDianRecommend:
             except Exception as e:
                 tb_info = traceback.format_exc()
                 self.LocalLog.error(f"{path}请求异常: {str(e)} \n {tb_info}")
-
-            time.sleep(random.randint(5, 10))
+            if attempt < self.MAX_RETRIES - 1:
+                time.sleep(random.randint(5, 10))
 
         # 所有重试失败,记录错误并返回None
         self.LocalLog.error(f"{path}达到最大重试次数")
@@ -346,6 +351,6 @@ if __name__ == '__main__':
     ZhongQingKanDianRecommend(
         platform="zhongqingkandian",
         mode="recommend",
-        rule_dict={'videos_cnt': {'min': 110, 'max': 0}, 'duration': {'min': 30, 'max': 1200}},
+        rule_dict={'videos_cnt': {'min': 2, 'max': 0}, 'duration': {'min': 30, 'max': 1200}},
         user_list=[{"uid": 81522822, "link": "中青看点推荐", "nick_name": "免不了俗"}]
     ).run()

+ 2 - 2
spider/crawler_online/zhongqingkandian_related_recommend.py

@@ -97,8 +97,8 @@ class ZhongQingKanDianRelatedRecommend:
             except Exception as e:
                 tb_info = traceback.format_exc()
                 self.LocalLog.error(f"{path}请求异常: {str(e)} \n {tb_info}")
-
-            time.sleep(random.randint(5,10))
+            if attempt < self.MAX_RETRIES - 1:
+                time.sleep(random.randint(5, 10))
 
         # 所有重试失败,记录错误并返回None
         self.LocalLog.error(f"{path}达到最大重试次数")