70def response(resp):
71 if search_type == 'web':
72
73 catch_bad_response(resp)
74
75 dom = html.fromstring(resp.text)
76
77 results = []
78
79 for result in eval_xpath_list(dom, results_xpath):
80 results.append(
81 {
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)),
85 }
86 )
87
88 return results
89
90 if search_type == 'images':
91
92 catch_bad_response(resp)
93
94 html_data = html.fromstring(resp.text)
95 html_sample = unescape(html.tostring(html_data, encoding='unicode'))
96
97 content_between_tags = extr(
98 html_sample, '{"location":"/images/search/', 'advRsyaSearchColumn":null}}', default="fail"
99 )
100 json_data = '{"location":"/images/search/' + content_between_tags + 'advRsyaSearchColumn":null}}'
101
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}}}'
105
106 json_resp = loads(json_data)
107
108 results = []
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)
118
119 results.append(
120 {
121 'title': title,
122 'url': source,
123 'img_src': fullsize_image,
124 'filesize': humanized_filesize,
125 'thumbnail_src': thumb,
126 'template': 'images.html',
127 'resolution': f'{width} x {height}',
128 }
129 )
130
131 return results
132
133 return []