diff --git a/searx/engines/google_images.py b/searx/engines/google_images.py index 6ec242b53..f0e9e27e3 100644 --- a/searx/engines/google_images.py +++ b/searx/engines/google_images.py @@ -24,6 +24,7 @@ Definitions`_. """ +import urllib from lxml import html from flask_babel import gettext from searx import logger @@ -77,6 +78,19 @@ def scrap_out_thumbs(dom): return ret_val +def scrap_img_by_id(script, data_id): + """Get full image URL by data-id in parent element + """ + img_url = '' + _script = script.split('\n') + for i, line in enumerate(_script): + if 'gstatic.com/images' in line and data_id in line: + url_line = _script[i + 1] + img_url = url_line.split('"')[1] + img_url = urllib.parse.unquote(img_url.replace(r'\u00', r'%')) + return img_url + + def request(query, params): """Google-Video search request""" @@ -133,6 +147,7 @@ def response(resp): # convert the text to dom dom = html.fromstring(resp.text) img_bas64_map = scrap_out_thumbs(dom) + img_src_script = eval_xpath(dom, '//script[contains(., "AF_initDataCallback({key: ")]')[1].text # parse results # @@ -142,8 +157,7 @@ def response(resp): #
/
AF_initDataCallback({key: 'ds:1', ... data:function(){return [ ... - # In this structure the ling to the origin PNG, JPG or whatever is given - # (we do not blow out the link there, you could still implement that) + # In this structure the link to the origin PNG, JPG or whatever is given # first link per image-div contains a with the data-iid for bas64 encoded image data:: #