9from searx.utils import humanize_bytes, eval_xpath, eval_xpath_list, extract_text, extr
71 if search_type ==
'web':
75 dom = html.fromstring(resp.text)
79 for result
in eval_xpath_list(dom, results_xpath):
82 'url': extract_text(eval_xpath(result, url_xpath)),
83 'title': extract_text(eval_xpath(result, title_xpath)),
84 'content': extract_text(eval_xpath(result, content_xpath)),
90 if search_type ==
'images':
94 html_data = html.fromstring(resp.text)
95 html_sample = unescape(html.tostring(html_data, encoding=
'unicode'))
97 content_between_tags = extr(
98 html_sample,
'{"location":"/images/search/',
'advRsyaSearchColumn":null}}', default=
"fail"
100 json_data =
'{"location":"/images/search/' + content_between_tags +
'advRsyaSearchColumn":null}}'
102 if content_between_tags ==
"fail":
103 content_between_tags = extr(html_sample,
'{"location":"/images/search/',
'false}}}')
104 json_data =
'{"location":"/images/search/' + content_between_tags +
'false}}}'
106 json_resp = loads(json_data)
109 for _, item_data
in json_resp[
'initialState'][
'serpList'][
'items'][
'entities'].items():
110 title = item_data[
'snippet'][
'title']
111 source = item_data[
'snippet'][
'url']
112 thumb = item_data[
'image']
113 fullsize_image = item_data[
'viewerData'][
'dups'][0][
'url']
114 height = item_data[
'viewerData'][
'dups'][0][
'h']
115 width = item_data[
'viewerData'][
'dups'][0][
'w']
116 filesize = item_data[
'viewerData'][
'dups'][0][
'fileSizeInBytes']
117 humanized_filesize = humanize_bytes(filesize)
123 'img_src': fullsize_image,
124 'filesize': humanized_filesize,
125 'thumbnail_src': thumb,
126 'template':
'images.html',
127 'resolution': f
'{width} x {height}',