summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorVenca24 <Venca24@users.noreply.github.com>2019-07-25 07:46:41 +0200
committerAlexandre Flament <alex@al-f.net>2019-07-25 07:46:41 +0200
commit87baa74a863ac74ae4c86bbfcb04148ba7f70696 (patch)
tree8a24ac0c78f4b3e5e5f02fecf327d613fb928d62 /searx/engines
parentd0dd296424d306049582a5a1b2fa01cbe7d7ce20 (diff)
downloadsearxng-87baa74a863ac74ae4c86bbfcb04148ba7f70696.tar.gz
searxng-87baa74a863ac74ae4c86bbfcb04148ba7f70696.zip
[fix] fixes google play engines and adds thumbnails to their results (#1612)
fix google play apps, google play apps, google play music engines xpath engine: thumbnail_xpath can define an optional thumbnail
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/xpath.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/searx/engines/xpath.py b/searx/engines/xpath.py
index 50f98d935..a5f30d86d 100644
--- a/searx/engines/xpath.py
+++ b/searx/engines/xpath.py
@@ -7,6 +7,7 @@ search_url = None
url_xpath = None
content_xpath = None
title_xpath = None
+thumbnail_xpath = False
paging = False
suggestion_xpath = ''
results_xpath = ''
@@ -40,7 +41,9 @@ def extract_text(xpath_results):
return ''.join(xpath_results)
else:
# it's a element
- text = html.tostring(xpath_results, encoding='unicode', method='text', with_tail=False)
+ text = html.tostring(
+ xpath_results, encoding='unicode', method='text', with_tail=False
+ )
text = text.strip().replace('\n', ' ')
return ' '.join(text.split())
@@ -105,7 +108,18 @@ def response(resp):
url = extract_url(result.xpath(url_xpath), search_url)
title = extract_text(result.xpath(title_xpath))
content = extract_text(result.xpath(content_xpath))
- results.append({'url': url, 'title': title, 'content': content})
+ tmp_result = {'url': url, 'title': title, 'content': content}
+
+ # add thumbnail if available
+ thumbnail = None
+ if thumbnail_xpath:
+ thumbnail = extract_url(
+ result.xpath(thumbnail_xpath), search_url
+ )
+ if thumbnail:
+ tmp_result['img_src'] = thumbnail
+
+ results.append(tmp_result)
else:
for url, title, content in zip(
(extract_url(x, search_url) for