48def response(resp):
49 results = []
50 dom = fromstring(resp.text)
51
52
53 first_result_index = page_size * (resp.search_params.get('pageno', 1) - 1)
54 all_results = eval_xpath_list(dom, results_xpath)
55 trimmed_results = all_results[first_result_index : first_result_index + page_size]
56
57
58 for result in trimmed_results:
59
60 raw_url = extract_url(eval_xpath_list(result, url_xpath, min_len=1), search_url)
61 cleaned_url = parse_qs(urlparse(raw_url).query).get('redirect_url', [''])[0]
62
63 title = extract_text(eval_xpath(result, title_xpath))
64 content = extract_text(eval_xpath(result, content_xpath))
65
66 results.append({'url': cleaned_url, 'title': title, 'content': content, 'is_onion': True})
67
68
69 for correction in eval_xpath_list(dom, correction_xpath):
70 results.append({'correction': extract_text(correction)})
71
72
73 number_of_results = eval_xpath(dom, number_of_results_xpath)
74 if number_of_results:
75 try:
76 results.append({'number_of_results': int(extract_text(number_of_results))})
77 except:
78 pass
79
80 return results