浏览代码

中青看点

zhangliang 3 天之前
父节点
当前提交
fe8d3dfaf8
共有 1 个文件被更改,包括 23 次插入12 次删除
  1. 23 12
      spider/crawler_author/zhongqingkandian_author.py

+ 23 - 12
spider/crawler_author/zhongqingkandian_author.py

@@ -7,8 +7,7 @@ import time
 import traceback
 import traceback
 from datetime import datetime
 from datetime import datetime
 import requests
 import requests
-from requests.adapters import HTTPAdapter
-from urllib3.util.retry import Retry
+
 
 
 sys.path.append(os.getcwd())
 sys.path.append(os.getcwd())
 from application.common.feishu import FsData
 from application.common.feishu import FsData
@@ -357,17 +356,29 @@ class ZhongQingKanDianAuthor:
             self.LocalLog.error(f"处理视频对象时发生异常: {e}\n{tb_info}")
             self.LocalLog.error(f"处理视频对象时发生异常: {e}\n{tb_info}")
 
 
     def convert_number(self,s):
     def convert_number(self,s):
-        if '万' in s:
-            try:
-                num = float(s.strip('万')) * 10000
-                return num
-            except ValueError:
-                self.LocalLog.info(f"无法将 '{s}' 转换为有效的数字。")
+        """解析数字字符串,处理包含'万'的情况"""
+        if isinstance(s, int):  # 如果已经是int,直接返回
+            return s
+        elif isinstance(s, str):  # 如果是字符串,处理'万'
+            if '万' in s:
+                try:
+                    num = float(s.strip('万')) * 10000
+                    return int(num) if num.is_integer() else num  # 整数返回int,小数返回float
+                except ValueError:
+                    print(f"无法将 '{s}' 转换为有效的数字。")
+                    return 0  # 默认返回0或其他默认值
+            else:
+                try:
+                    return int(s)  # 尝试转换为int
+                except ValueError:
+                    try:
+                        return float(s)  # 尝试转换为float
+                    except ValueError:
+                        print(f"'{s}' 不是有效的数字格式。")
+                        return 0  # 默认返回0或其他默认值
         else:
         else:
-            try:
-                return int(s)
-            except ValueError:
-                self.LocalLog.info(f"'{s}' 不是有效的数字格式。")
+            print(f"不支持的类型: {type(s).__name__}")
+            return 0  # 非int/str类型返回默认值
 
 
     def run(self):
     def run(self):
         """
         """