Browse Source

2024-05-05
上线抖音搜索

罗俊辉 10 months ago
parent
commit
b6e0e1b9fd
1 changed files with 18 additions and 14 deletions
  1. 18 14
      applications/search/dy_search.py

+ 18 - 14
applications/search/dy_search.py

@@ -28,21 +28,25 @@ def douyin_search(keyword, sensitive_words):
     }
 
     response = requests.request("POST", url, headers=headers, data=payload)
-    dt_list = response.json()['data']['data']
-    L = []
-    for obj in dt_list:
-        try:
-            title = obj['video_desc']
-            video_id = obj['video_id']
-            if sensitive_flag(sensitive_words, title):
-                res = douyin_detail(video_id)
-                L.append(res)
-                return L
-            else:
+    try:
+        dt_list = response.json()['data']['data']
+        L = []
+        for obj in dt_list:
+            try:
+                title = obj['video_desc']
+                video_id = obj['video_id']
+                if sensitive_flag(sensitive_words, title):
+                    res = douyin_detail(video_id)
+                    L.append(res)
+                    return L
+                else:
+                    continue
+            except Exception as e:
                 continue
-        except Exception as e:
-            continue
-    return []
+        return []
+    except:
+        print("search_fail---{}".format(keyword))
+        return []
 
 
 def douyin_detail(video_id):