107def response(resp):
108 """Get response from google's search request"""
109 results = []
110
111 detect_google_sorry(resp)
112 data_image_map = parse_data_images(resp.text)
113
114
115 dom = html.fromstring(resp.text)
116
117
118 for result in eval_xpath_list(dom, '//div[contains(@class, "g ")]'):
119
120 thumbnail = eval_xpath_getindex(result, './/img/@src', 0, None)
121 if thumbnail:
122 if thumbnail.startswith('data:image'):
123 img_id = eval_xpath_getindex(result, './/img/@id', 0, None)
124 if img_id:
125 thumbnail = data_image_map.get(img_id)
126 else:
127 thumbnail = None
128
129 title = extract_text(eval_xpath_getindex(result, './/a/h3[1]', 0))
130 url = eval_xpath_getindex(result, './/a/h3[1]/../@href', 0)
131
132 c_node = eval_xpath_getindex(result, './/div[contains(@class, "ITZIwc")]', 0)
133 content = extract_text(c_node)
134 pub_info = extract_text(eval_xpath(result, './/div[contains(@class, "gqF9jc")]'))
135
136 results.append(
137 {
138 'url': url,
139 'title': title,
140 'content': content,
141 'author': pub_info,
142 'thumbnail': thumbnail,
143 'iframe_src': get_embeded_stream_url(url),
144 'template': 'videos.html',
145 }
146 )
147
148
149 for suggestion in eval_xpath_list(dom, suggestion_xpath):
150
151 results.append({'suggestion': extract_text(suggestion)})
152
153 return results