Browse Source

[fix] do not crash if publication date is missing in pubmed engine

Adam Tauber 7 years ago
parent
commit
1088c2a75d
1 changed files with 8 additions and 5 deletions
  1. 8 5
      searx/engines/pubmed.py

+ 8 - 5
searx/engines/pubmed.py

@@ -84,15 +84,18 @@ def response(resp):
                     content = content[0:300] + "..."
         # TODO: center snippet on query term
 
-        publishedDate = datetime.strptime(entry.xpath('.//DateCreated/Year')[0].text
-                                          + '-' + entry.xpath('.//DateCreated/Month')[0].text
-                                          + '-' + entry.xpath('.//DateCreated/Day')[0].text, '%Y-%m-%d')
-
         res_dict = {'url': url,
                     'title': title,
-                    'publishedDate': publishedDate,
                     'content': content}
 
+        try:
+            publishedDate = datetime.strptime(entry.xpath('.//DateCreated/Year')[0].text
+                                              + '-' + entry.xpath('.//DateCreated/Month')[0].text
+                                              + '-' + entry.xpath('.//DateCreated/Day')[0].text, '%Y-%m-%d')
+            res_dict['publishedDate'] = publishedDate
+        except:
+            pass
+
         results.append(res_dict)
 
         return results