on master help sign in
[fix] fixes google play engines and adds thumbnails to their results (#1612)
87baa74Venca24
searx/engines/xpath.py+16−2
@@ -7,6 +7,7 @@ search_url = None
7url_xpath = None
7url_xpath = None
8content_xpath = None
8content_xpath = None
9title_xpath = None
9title_xpath = None
10+thumbnail_xpath = False
10paging = False
11paging = False
11suggestion_xpath = ''
12suggestion_xpath = ''
12results_xpath = ''
13results_xpath = ''
@@ -40,7 +41,9 @@ def extract_text(xpath_results):
40 return ''.join(xpath_results)
41 return ''.join(xpath_results)
41 else:
42 else:
42 # it's a element
43 # it's a element
44+ text = html.tostring(
43− text = html.tostring(xpath_results, encoding='unicode', method='text', with_tail=False)
45+ xpath_results, encoding='unicode', method='text', with_tail=False
46+ )
44 text = text.strip().replace('\n', ' ')
47 text = text.strip().replace('\n', ' ')
45 return ' '.join(text.split())
48 return ' '.join(text.split())
46
49
@@ -105,7 +108,18 @@ def response(resp):
105 url = extract_url(result.xpath(url_xpath), search_url)
108 url = extract_url(result.xpath(url_xpath), search_url)
106 title = extract_text(result.xpath(title_xpath))
109 title = extract_text(result.xpath(title_xpath))
107 content = extract_text(result.xpath(content_xpath))
110 content = extract_text(result.xpath(content_xpath))
108− results.append({'url': url, 'title': title, 'content': content})
111+ tmp_result = {'url': url, 'title': title, 'content': content}
112+
113+ # add thumbnail if available
114+ thumbnail = None
115+ if thumbnail_xpath:
116+ thumbnail = extract_url(
117+ result.xpath(thumbnail_xpath), search_url
118+ )
119+ if thumbnail:
120+ tmp_result['img_src'] = thumbnail
121+
122+ results.append(tmp_result)
109 else:
123 else:
110 for url, title, content in zip(
124 for url, title, content in zip(
111 (extract_url(x, search_url) for
125 (extract_url(x, search_url) for
searx/settings.yml+21−15
@@ -311,31 +311,37 @@ engines:
311 shortcut : gos
311 shortcut : gos
312
312
313 - name : google play apps
313 - name : google play apps
314− engine : xpath
314+ engine : xpath
315− search_url : https://play.google.com/store/search?q={query}&c=apps
315+ search_url : https://play.google.com/store/search?q={query}&c=apps
316+ results_xpath : '//div[@class="WHE7ib mpg5gc"]'
317+ title_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a'
316− url_xpath : //a[@class="title"]/@href
318+ url_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a/@href'
317− title_xpath : //a[@class="title"]
318− content_xpath : //a[@class="subtitle"]
319+ content_xpath : './/div[@class="RZEgze"]//a[@class="mnKHRc"]'
320+ thumbnail_xpath : './/div[@class="uzcko"]/div/span[1]/img/@data-src'
319 categories : files
321 categories : files
320 shortcut : gpa
322 shortcut : gpa
321 disabled : True
323 disabled : True
322
324
323 - name : google play movies
325 - name : google play movies
324− engine : xpath
326+ engine : xpath
325− search_url : https://play.google.com/store/search?q={query}&c=movies
327+ search_url : https://play.google.com/store/search?q={query}&c=movies
328+ results_xpath : '//div[@class="WHE7ib mpg5gc"]'
329+ title_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a'
326− url_xpath : //a[@class="title"]/@href
330+ url_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a/@href'
327− title_xpath : //a[@class="title"]/@title
328− content_xpath : //a[contains(@class, "subtitle")]
331+ content_xpath : './/div[@class="RZEgze"]//a[@class="mnKHRc"]'
332+ thumbnail_xpath : './/div[@class="uzcko"]/div/span[1]/img/@data-src'
329 categories : videos
333 categories : videos
330 shortcut : gpm
334 shortcut : gpm
331 disabled : True
335 disabled : True
332
336
333 - name : google play music
337 - name : google play music
334− engine : xpath
338+ engine : xpath
335− search_url : https://play.google.com/store/search?q={query}&c=music
339+ search_url : https://play.google.com/store/search?q={query}&c=music
340+ results_xpath : '//div[@class="WHE7ib mpg5gc"]'
341+ title_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a'
336− url_xpath : //a[@class="title"]/@href
342+ url_xpath : './/div[@class="RZEgze"]//div[@title and not(@title="")]/a/@href'
337− title_xpath : //a[@class="title"]
338− content_xpath : //a[@class="subtitle"]
343+ content_xpath : './/div[@class="RZEgze"]//a[@class="mnKHRc"]'
344+ thumbnail_xpath : './/div[@class="uzcko"]/div/span[1]/img/@data-src'
339 categories : music
345 categories : music
340 shortcut : gps
346 shortcut : gps
341 disabled : True
347 disabled : True