|
@@ -24,6 +24,7 @@ Definitions`_.
|
|
|
|
|
|
"""
|
|
"""
|
|
|
|
|
|
|
|
+import urllib
|
|
from lxml import html
|
|
from lxml import html
|
|
from flask_babel import gettext
|
|
from flask_babel import gettext
|
|
from searx import logger
|
|
from searx import logger
|
|
@@ -77,6 +78,19 @@ def scrap_out_thumbs(dom):
|
|
return ret_val
|
|
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):
|
|
def request(query, params):
|
|
"""Google-Video search request"""
|
|
"""Google-Video search request"""
|
|
|
|
|
|
@@ -133,6 +147,7 @@ def response(resp):
|
|
|
|
|
|
dom = html.fromstring(resp.text)
|
|
dom = html.fromstring(resp.text)
|
|
img_bas64_map = scrap_out_thumbs(dom)
|
|
img_bas64_map = scrap_out_thumbs(dom)
|
|
|
|
+ img_src_script = eval_xpath(dom, '//script[contains(., "AF_initDataCallback({key: ")]')[1].text
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -142,8 +157,7 @@ def response(resp):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
+
|
|
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -186,12 +200,17 @@ def response(resp):
|
|
pub_descr = extract_text(pub_nodes[0])
|
|
pub_descr = extract_text(pub_nodes[0])
|
|
pub_source = extract_text(pub_nodes[1])
|
|
pub_source = extract_text(pub_nodes[1])
|
|
|
|
|
|
|
|
+ img_src_id = eval_xpath(img_node, '../../../@data-id')[0]
|
|
|
|
+ src_url = scrap_img_by_id(img_src_script, img_src_id)
|
|
|
|
+ if not src_url:
|
|
|
|
+ src_url = thumbnail_src
|
|
|
|
+
|
|
results.append({
|
|
results.append({
|
|
'url': url,
|
|
'url': url,
|
|
'title': img_alt,
|
|
'title': img_alt,
|
|
'content': pub_descr,
|
|
'content': pub_descr,
|
|
'source': pub_source,
|
|
'source': pub_source,
|
|
- 'img_src': url,
|
|
+ 'img_src': src_url,
|
|
|
|
|
|
'thumbnail_src': thumbnail_src,
|
|
'thumbnail_src': thumbnail_src,
|
|
'template': 'images.html'
|
|
'template': 'images.html'
|