98def response(resp):
99 """Get response from google's search request"""
100 results = []
101
102 detect_google_sorry(resp)
103
104
105 dom = html.fromstring(resp.text)
106
107
108 for result in eval_xpath_list(dom, '//div[contains(@class, "g ")]'):
109
110 img_src = eval_xpath_getindex(result, './/img/@src', 0, None)
111 if img_src is None:
112 continue
113
114 title = extract_text(eval_xpath_getindex(result, './/a/h3[1]', 0))
115 url = eval_xpath_getindex(result, './/a/h3[1]/../@href', 0)
116
117 c_node = eval_xpath_getindex(result, './/div[@class="ITZIwc"]', 0)
118 content = extract_text(c_node)
119 pub_info = extract_text(eval_xpath(result, './/div[@class="gqF9jc"]'))
120
121 results.append(
122 {
123 'url': url,
124 'title': title,
125 'content': content,
126 'author': pub_info,
127 'thumbnail': img_src,
128 'template': 'videos.html',
129 }
130 )
131
132
133 for suggestion in eval_xpath_list(dom, suggestion_xpath):
134
135 results.append({'suggestion': extract_text(suggestion)})
136
137 return results