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