|
@@ -219,9 +219,17 @@ def response(resp):
|
219
|
219
|
# convert the text to dom
|
220
|
220
|
dom = html.fromstring(resp.text)
|
221
|
221
|
|
222
|
|
- instant_answer = dom.xpath('//div[@id="_vBb"]//text()')
|
|
222
|
+ instant_answer = dom.xpath('//div[contains(@id, "ires")]//div[contains(@class, "hp-xpdbox")]')
|
223
|
223
|
if instant_answer:
|
224
|
|
- results.append({'answer': u' '.join(instant_answer)})
|
|
224
|
+ answer_re = r'(?P<prefix><a\s+href=")\/url\?q=(?P<url>[^"]+?)\&\;[^"]*(?P<suffix>"\s*>)'
|
|
225
|
+ answer_subst = "\\g<prefix>\\g<url>\\g<suffix>"
|
|
226
|
+ answer_html = ['<br>']
|
|
227
|
+ for element in instant_answer:
|
|
228
|
+ answer_html.append(etree.tostring(element, method="html"))
|
|
229
|
+ answer_str = u' '.join(answer_html)
|
|
230
|
+ answer_fixed = re.sub(answer_re, answer_subst, answer_str, 0, re.MULTILINE)
|
|
231
|
+ results.append({'answer': answer_fixed})
|
|
232
|
+
|
225
|
233
|
try:
|
226
|
234
|
results_num = int(dom.xpath('//div[@id="resultStats"]//text()')[0]
|
227
|
235
|
.split()[1].replace(',', ''))
|