Explorar el Código

Merge 9a30820e5713eca175788c4e7ea61d1320e6c481 into f82ead3e303d75ba63a370dc038311e172e1330d

Nícholas Kegler hace 6 años
padre
commit
1f989999c8
Ninguna cuenta está vinculada al correo electrónico del colaborador
Se han modificado 2 ficheros con 11 adiciones y 3 borrados
  1. 10
    2
      searx/engines/google.py
  2. 1
    1
      searx/templates/oscar/results.html

+ 10
- 2
searx/engines/google.py Ver fichero

@@ -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>[^"]+?)\&amp\;[^"]*(?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(',', ''))

+ 1
- 1
searx/templates/oscar/results.html Ver fichero

@@ -31,7 +31,7 @@
31 31
             {% if answers %}
32 32
             {% for answer in answers %}
33 33
             <div class="result well">
34
-                <span>{{ answer }}</span>
34
+                <span>{{ answer|safe }}</span>
35 35
             </div>
36 36
             {% endfor %}
37 37
             {% endif %}