logo

searx

My custom branche(s) on searx, a meta-search engine
commit: 37035b7a40ec76ab582908827d2d25158f10301e
parent: e061c6e059ab8055f5b95f162d791fa9c9c422d6
Author: Adam Tauber <asciimoo@gmail.com>
Date:   Sun, 31 Jan 2016 13:24:09 +0100

[fix] gigablast params ++ json response format

Diffstat:

Msearx/engines/gigablast.py28++++++++++++----------------
1 file changed, 12 insertions(+), 16 deletions(-)

diff --git a/searx/engines/gigablast.py b/searx/engines/gigablast.py @@ -10,11 +10,11 @@ @parse url, title, content """ -from urllib import urlencode from cgi import escape -from lxml import etree +from json import loads from random import randint from time import time +from urllib import urlencode # engine dependent config categories = ['general'] @@ -27,11 +27,11 @@ safesearch = True base_url = 'https://gigablast.com/' search_string = 'search?{query}'\ '&n={number_of_results}'\ + '&c=main'\ '&s={offset}'\ - '&format=xml'\ + '&format=json'\ '&qh=0'\ - '&rxiyd={rxiyd}'\ - '&rand={rand}'\ + '&rxiwd={rxiwd}'\ '&qlang={lang}'\ '&ff={safesearch}' @@ -59,8 +59,8 @@ def request(query, params): search_path = search_string.format(query=urlencode({'q': query}), offset=offset, number_of_results=number_of_results, - rxiyd=randint(10000, 10000000), - rand=int(time()), + rxiwd=1, + # rand=int(time()), lang=language, safesearch=safesearch) @@ -73,18 +73,14 @@ def request(query, params): def response(resp): results = [] - dom = etree.fromstring(resp.content) - # parse results - for result in dom.xpath(results_xpath): - url = result.xpath(url_xpath)[0].text - title = result.xpath(title_xpath)[0].text - content = escape(result.xpath(content_xpath)[0].text) + response_json = loads(resp.text) + for result in response_json['results']: # append result - results.append({'url': url, - 'title': title, - 'content': content}) + results.append({'url': result['url'], + 'title': escape(result['title']), + 'content': escape(result['sum'])}) # return results return results