@@ -24,6 +24,7 @@ Definitions`_.
2424
2525"""
2626
27+import urllib
2728from lxml import html
2829from flask_babel import gettext
2930from searx import logger
@@ -77,6 +78,19 @@ def scrap_out_thumbs(dom):
7778 return ret_val
7879
7980
81+def scrap_img_by_id(script, data_id):
82+ """Get full image URL by data-id in parent element
83+ """
84+ img_url = ''
85+ _script = script.split('\n')
86+ for i, line in enumerate(_script):
87+ if 'gstatic.com/images' in line and data_id in line:
88+ url_line = _script[i + 1]
89+ img_url = url_line.split('"')[1]
90+ img_url = urllib.parse.unquote(img_url.replace(r'\u00', r'%'))
91+ return img_url
92+
93+
8094def request(query, params):
8195 """Google-Video search request"""
8296
@@ -133,6 +147,7 @@ def response(resp):
133147 # convert the text to dom
134148 dom = html.fromstring(resp.text)
135149 img_bas64_map = scrap_out_thumbs(dom)
150+ img_src_script = eval_xpath(dom, '//script[contains(., "AF_initDataCallback({key: ")]')[1].text
136151
137152 # parse results
138153 #
@@ -142,8 +157,7 @@ def response(resp):
142157 # <div jsmodel="tTXmib"> / <div jsaction="..." data-id="..."
143158 # The data-id matches to a item in a json-data structure in::
144159 # <script nonce="I+vqelcy/01CKiBJi5Z1Ow">AF_initDataCallback({key: 'ds:1', ... data:function(){return [ ...
145− # In this structure the ling to the origin PNG, JPG or whatever is given
146− # (we do not blow out the link there, you could still implement that)
160+ # In this structure the link to the origin PNG, JPG or whatever is given
147161 # first link per image-div contains a <img> with the data-iid for bas64 encoded image data::
148162 # <img class="rg_i Q4LuWd" data-iid="0"
149163 # second link per image-div is the target link::
@@ -186,12 +200,17 @@ def response(resp):
186200 pub_descr = extract_text(pub_nodes[0])
187201 pub_source = extract_text(pub_nodes[1])
188202
203+ img_src_id = eval_xpath(img_node, '../../../@data-id')[0]
204+ src_url = scrap_img_by_id(img_src_script, img_src_id)
205+ if not src_url:
206+ src_url = thumbnail_src
207+
189208 results.append({
190209 'url': url,
191210 'title': img_alt,
192211 'content': pub_descr,
193212 'source': pub_source,
194− 'img_src': url,
213+ 'img_src': src_url,
195214 # 'img_format': img_format,
196215 'thumbnail_src': thumbnail_src,
197216 'template': 'images.html'