diff options
author | a01200356 <a01200356@itesm.mx> | 2015-12-30 00:53:15 -0600 |
---|---|---|
committer | a01200356 <a01200356@itesm.mx> | 2015-12-30 00:53:15 -0600 |
commit | be54e5269a982e272e2fe8a5064ed898373c9063 (patch) | |
tree | b2faba6828ca1513156afa0fb762447f4fb4006d /searx/engines/wolframalpha_noapi.py | |
parent | 5ed8f4da80ecd119173d7db871256be8484a9ecb (diff) | |
download | searxng-be54e5269a982e272e2fe8a5064ed898373c9063.tar.gz searxng-be54e5269a982e272e2fe8a5064ed898373c9063.zip |
Add tests for the Wolfram Alpha engines (both API and NO API versions)
Diffstat (limited to 'searx/engines/wolframalpha_noapi.py')
-rw-r--r-- | searx/engines/wolframalpha_noapi.py | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/searx/engines/wolframalpha_noapi.py b/searx/engines/wolframalpha_noapi.py index 23e912a1e..9d3afe658 100644 --- a/searx/engines/wolframalpha_noapi.py +++ b/searx/engines/wolframalpha_noapi.py @@ -7,8 +7,8 @@ # @stable no # @parse answer -import re -import json +from re import search +from json import loads from urllib import urlencode # search-url @@ -26,6 +26,8 @@ def request(query, params): # get response from search-request def response(resp): results = [] + webpage = resp.text + line = None # the answer is inside a js function # answer can be located in different 'pods', although by default it should be in pod_0200 @@ -35,7 +37,7 @@ def response(resp): # get line that matches the pattern for pattern in possible_locations: try: - line = re.search(pattern, resp.text).group(1) + line = search(pattern, webpage).group(1) break except AttributeError: continue @@ -45,7 +47,7 @@ def response(resp): # extract answer from json answer = line[line.find('{'):line.rfind('}')+1] - answer = json.loads(answer.encode('unicode-escape')) + answer = loads(answer.encode('unicode-escape')) answer = answer['stringified'].decode('unicode-escape') results.append({'answer': answer}) |