mirror of
https://github.com/searxng/searxng.git
synced 2025-08-02 18:12:21 +02:00
Add thumbnails in images results
- Modify engines to create/fetch an URL for the thumbnails - Modify themes to show thumbnails instead of full images. In Courgette, the result is not very beautiful. Should we change it ?
This commit is contained in:
parent
edd9d31180
commit
cb4a3fe598
9 changed files with 44 additions and 8 deletions
|
@ -14,6 +14,7 @@
|
|||
from urllib import urlencode
|
||||
from urlparse import urljoin
|
||||
from lxml import html
|
||||
import re
|
||||
|
||||
# engine dependent config
|
||||
categories = ['images']
|
||||
|
@ -37,20 +38,25 @@ def response(resp):
|
|||
results = []
|
||||
|
||||
dom = html.fromstring(resp.text)
|
||||
regex = re.compile('3\.jpg.*$')
|
||||
|
||||
# parse results
|
||||
for result in dom.xpath('//div[@class="photo"]'):
|
||||
link = result.xpath('.//a')[0]
|
||||
url = urljoin(base_url, link.attrib.get('href'))
|
||||
title = result.xpath('.//div[@class="title"]//text()')[0]
|
||||
img_src = link.xpath('.//img')[0].attrib['src']
|
||||
thumbnail_src = link.xpath('.//img')[0].attrib['src']
|
||||
# To have a bigger thumbnail, uncomment the next line
|
||||
#thumbnail_src = regex.sub('4.jpg', thumbnail_src)
|
||||
content = result.xpath('.//div[@class="info"]//text()')[0]
|
||||
img_src = regex.sub('2048.jpg', thumbnail_src)
|
||||
|
||||
# append result
|
||||
results.append({'url': url,
|
||||
'title': title,
|
||||
'img_src': img_src,
|
||||
'content': content,
|
||||
'thumbnail_src': thumbnail_src,
|
||||
'template': 'images.html'})
|
||||
|
||||
# return results
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue