265def response(resp) -> EngineResults:
266 """Scrap *results* from the response (see :ref:`result types`)."""
267 results = EngineResults()
268
269 if no_result_for_http_status and resp.status_code in no_result_for_http_status:
270 return results
271
272 raise_for_httperror(resp)
273
274 if not resp.text:
275 return results
276
277 dom = html.fromstring(resp.text)
278 is_onion = 'onions' in categories
279
280 if results_xpath:
281 for result in eval_xpath_list(dom, results_xpath):
282
283 url = extract_url(eval_xpath_list(result, url_xpath, min_len=1), search_url)
284 title = extract_text(eval_xpath_list(result, title_xpath, min_len=1))
285 content = extract_text(eval_xpath_list(result, content_xpath))
286 tmp_result = {'url': url, 'title': title, 'content': content}
287
288
289 if thumbnail_xpath:
290 thumbnail_xpath_result = eval_xpath_list(result, thumbnail_xpath)
291 if len(thumbnail_xpath_result) > 0:
292 tmp_result['thumbnail'] = extract_url(thumbnail_xpath_result, search_url)
293
294
295 if cached_xpath:
296 tmp_result['cached_url'] = cached_url + extract_text(eval_xpath_list(result, cached_xpath, min_len=1))
297
298 if is_onion:
299 tmp_result['is_onion'] = True
300
301 results.append(tmp_result)
302
303 else:
304 if cached_xpath:
305 for url, title, content, cached in zip(
306 (extract_url(x, search_url) for x in eval_xpath_list(dom, url_xpath)),
307 map(extract_text, eval_xpath_list(dom, title_xpath)),
308 map(extract_text, eval_xpath_list(dom, content_xpath)),
309 map(extract_text, eval_xpath_list(dom, cached_xpath)),
310 ):
311 results.append(
312 {
313 'url': url,
314 'title': title,
315 'content': content,
316 'cached_url': cached_url + cached,
317 'is_onion': is_onion,
318 }
319 )
320 else:
321 for url, title, content in zip(
322 (extract_url(x, search_url) for x in eval_xpath_list(dom, url_xpath)),
323 map(extract_text, eval_xpath_list(dom, title_xpath)),
324 map(extract_text, eval_xpath_list(dom, content_xpath)),
325 ):
326 results.append({'url': url, 'title': title, 'content': content, 'is_onion': is_onion})
327
328 if suggestion_xpath:
329 for suggestion in eval_xpath(dom, suggestion_xpath):
330 results.append({'suggestion': extract_text(suggestion)})
331
332 logger.debug("found %s results", len(results))
333 return results