1
0
mirror of https://github.com/searx/searx synced 2024-12-11 16:35:20 +01:00

[fix] use html result page in google images (previous endpoint stopped working)

This commit is contained in:
Adam Tauber 2018-06-14 11:39:54 +02:00
parent 8dec30123e
commit 57e7e9da98

View File

@ -13,7 +13,7 @@
from datetime import date, timedelta from datetime import date, timedelta
from json import loads from json import loads
from lxml import html from lxml import html
from searx.url_utils import urlencode from searx.url_utils import urlencode, urlparse, parse_qs
# engine dependent config # engine dependent config
@ -25,10 +25,9 @@ number_of_results = 100
search_url = 'https://www.google.com/search'\ search_url = 'https://www.google.com/search'\
'?{query}'\ '?{query}'\
'&asearch=ichunk'\
'&async=_id:rg_s,_pms:s'\
'&tbm=isch'\ '&tbm=isch'\
'&yv=2'\ '&gbv=1'\
'&sa=G'\
'&{search_options}' '&{search_options}'
time_range_attr = "qdr:{range}" time_range_attr = "qdr:{range}"
time_range_custom_attr = "cdr:1,cd_min:{start},cd_max{end}" time_range_custom_attr = "cdr:1,cd_min:{start},cd_max{end}"
@ -66,30 +65,22 @@ def request(query, params):
def response(resp): def response(resp):
results = [] results = []
g_result = loads(resp.text) dom = html.fromstring(resp.text)
dom = html.fromstring(g_result[1][1])
# parse results # parse results
for result in dom.xpath('//div[@data-ved]'): for img in dom.xpath('//a'):
r = {
try: 'title': u' '.join(img.xpath('.//div[class="rg_ilmbg"]//text()')),
metadata = loads(''.join(result.xpath('./div[contains(@class, "rg_meta")]/text()'))) 'content': '',
except: 'template': 'images.html',
continue }
url = urlparse(img.xpath('.//@href')[0])
thumbnail_src = metadata['tu'] query = parse_qs(url.query)
r['url'] = query['imgrefurl'][0]
# http to https r['img_src'] = query['imgurl'][0]
thumbnail_src = thumbnail_src.replace("http://", "https://") r['thumbnail_src'] = r['img_src']
# append result # append result
results.append({'url': metadata['ru'], results.append(r)
'title': metadata['pt'],
'content': metadata['s'],
'thumbnail_src': thumbnail_src,
'img_src': metadata['ou'],
'template': 'images.html'})
# return results # return results
return results return results