Prechádzať zdrojové kódy

update:优化提取爬虫必填属性异常时容错性

dongzhaorui 2 rokov pred
rodič
commit
78d502d567

+ 2 - 2
FworkSpider/feapder/core/parser_control.py

@@ -500,8 +500,8 @@ class PaserControl(threading.Thread):
         status_code = getattr(response, "status_code", -1)
 
         item = getattr(request, "item", {})
-        site = getattr(parser, "site", None) or (item.get("site") if isinstance(item, dict) else getattr(item, "site", "unknown"))
-        channel = item.get("channel") if isinstance(item, dict) else getattr(item, "channel", "unknown")
+        site = (item.get("site") if isinstance(item, dict) else getattr(item, "site", None)) or getattr(parser, "site", None) or "unknown"
+        channel = (item.get("channel") if isinstance(item, dict) else getattr(item, "channel", None)) or getattr(parser, "channel", None) or "unknown"
         code = (item.get("code") or item.get("spidercode")) if isinstance(item, dict) else getattr(item, "spidercode", "unknown")
         business_type = parser.__business_type__  # 爬虫业务类型
         run_time = tools.get_current_date(date_format="%Y-%m-%d")  # 运行时间,单位:天