Browse Source

[mod] add more error handling to json engine

Adam Tauber 7 years ago
parent
commit
181f1c6305
1 changed files with 8 additions and 2 deletions
  1. 8
    2
      searx/engines/json_engine.py

+ 8
- 2
searx/engines/json_engine.py View File

@@ -98,10 +98,16 @@ def response(resp):
98 98
     results = []
99 99
     json = loads(resp.text)
100 100
     if results_query:
101
-        for result in query(json, results_query)[0]:
101
+        rs = query(json, results_query)
102
+        if not len(rs):
103
+            return results
104
+        for result in rs[0]:
102 105
             url = query(result, url_query)[0]
103 106
             title = query(result, title_query)[0]
104
-            content = query(result, content_query)[0]
107
+            try:
108
+                content = query(result, content_query)[0]
109
+            except:
110
+                content = ""
105 111
             results.append({'url': url, 'title': title, 'content': content})
106 112
     else:
107 113
         for url, title, content in zip(