Browse Source

[fix] unescape htmlentities in wolframalpha_noapi's answer

a01200356 9 years ago
parent
commit
576d37f256
2 changed files with 8 additions and 2 deletions
  1. 6 1
      searx/engines/wolframalpha_noapi.py
  2. 2 1
      searx/settings.yml

+ 6 - 1
searx/engines/wolframalpha_noapi.py

@@ -12,6 +12,7 @@ from re import search, sub
 from json import loads
 from json import loads
 from urllib import urlencode
 from urllib import urlencode
 from lxml import html
 from lxml import html
+import HTMLParser
 
 
 # search-url
 # search-url
 url = 'http://www.wolframalpha.com/'
 url = 'http://www.wolframalpha.com/'
@@ -62,7 +63,11 @@ def response(resp):
         # extract answer from json
         # extract answer from json
         answer = line[line.find('{'):line.rfind('}')+1]
         answer = line[line.find('{'):line.rfind('}')+1]
         answer = loads(answer.encode('unicode-escape'))
         answer = loads(answer.encode('unicode-escape'))
-        answer = answer['stringified'].decode('unicode-escape')
+        answer = answer['stringified']
+
+        # clean plaintext answer
+        h = HTMLParser.HTMLParser()
+        answer = h.unescape(answer.decode('unicode-escape'))
         answer = sub(r'\\', '', answer)
         answer = sub(r'\\', '', answer)
 
 
         results.append({'answer': answer})
         results.append({'answer': answer})

+ 2 - 1
searx/settings.yml

@@ -305,9 +305,10 @@ engines:
     # You can use the engine using the official stable API, but you need an API key
     # You can use the engine using the official stable API, but you need an API key
     # See : http://products.wolframalpha.com/api/
     # See : http://products.wolframalpha.com/api/
     #    engine : wolframalpha_api
     #    engine : wolframalpha_api
-    #    api_key: '5952JX-X52L3VKWT8' # required!
+    #    api_key: '' # required!
     engine : wolframalpha_noapi
     engine : wolframalpha_noapi
     timeout: 6.0
     timeout: 6.0
+    disabled : True
 
 
 #The blekko technology and team have joined IBM Watson! -> https://blekko.com/
 #The blekko technology and team have joined IBM Watson! -> https://blekko.com/
 #  - name : blekko images
 #  - name : blekko images