소스 검색

2024-0514-搜索策略实验上线

罗俊辉 1 년 전
부모
커밋
0e600d84ef
1개의 변경된 파일23개의 추가작업 그리고 14개의 파일을 삭제
  1. 23 14
      applications/search/xigua_search.py

+ 23 - 14
applications/search/xigua_search.py

@@ -207,20 +207,29 @@ def xigua_search(keyword):
     )
     if result_list:
         for item in result_list:
-            url = item.xpath("@href")[0]
-            duration_str = str(item.xpath("./span/text()")[0])
-            duration = int(duration_str.split(":")[0]) * 60 + int(duration_str.split(":")[1])
-            title = item.xpath("@title")[0]
-            real_title = bytes(str(title), "latin1").decode()
-            if sensitive_flag(sensitive_words, real_title) and duration <= 300:
-                try:
-                    res = XiGuaFunctions().get_video_info(url[1:])
-                    if res:
-                        return [res]
-                    else:
-                        continue
-                except Exception as e:
-                    print(e)
+            try:
+                url = item.xpath("@href")[0]
+                duration_str = str(item.xpath("./span/text()")[0])
+                duration_obj = duration_str.split(":")
+                if len(duration_obj) == 3:
+                    duration = 100000
+                elif len(duration_obj) == 2:
+                    duration = int(duration_str.split(":")[0]) * 60 + int(duration_str.split(":")[1])
+                else:
+                    duration = 10000
+                title = item.xpath("@title")[0]
+                real_title = bytes(str(title), "latin1").decode()
+                if sensitive_flag(sensitive_words, real_title) and duration <= 300:
+                    try:
+                        res = XiGuaFunctions().get_video_info(url[1:])
+                        if res:
+                            return [res]
+                        else:
+                            continue
+                    except Exception as e:
+                        print(e)
+            except Exception as e:
+                print(e)
         return []
     else:
         return []