From f0684a5bb5860c2b9caffefb47dc55781092819e Mon Sep 17 00:00:00 2001 From: piplongrun Date: Wed, 12 Feb 2020 23:58:50 +0100 Subject: [PATCH 1/2] Add eTools engine --- searx/engines/etools.py | 54 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 searx/engines/etools.py diff --git a/searx/engines/etools.py b/searx/engines/etools.py new file mode 100644 index 00000000..a9eb0980 --- /dev/null +++ b/searx/engines/etools.py @@ -0,0 +1,54 @@ +""" + eTools (Web) + + @website https://www.etools.ch + @provide-api no + @using-api no + @results HTML + @stable no (HTML can change) + @parse url, title, content +""" + +from lxml import html +from searx.engines.xpath import extract_text +from searx.url_utils import quote +from searx.utils import eval_xpath + +categories = ['general'] +paging = False +language_support = False +safesearch = True + +base_url = 'https://www.etools.ch' +search_path = '/searchAdvancedSubmit.do'\ + '?query={search_term}'\ + '&pageResults=20'\ + '&safeSearch={safesearch}' + + +def request(query, params): + if params['safesearch']: + safesearch = 'true' + else: + safesearch = 'false' + + params['url'] = base_url + search_path.format(search_term=quote(query), safesearch=safesearch) + + return params + + +def response(resp): + results = [] + + dom = html.fromstring(resp.text) + + for result in eval_xpath(dom, '//table[@class="result"]//td[@class="record"]'): + url = eval_xpath(result, './a/@href')[0] + title = extract_text(eval_xpath(result, './a//text()')) + content = extract_text(eval_xpath(result, './/div[@class="text"]//text()')) + + results.append({'url': url, + 'title': title, + 'content': content}) + + return results From e1b60106b7dab37fe29cb68c9b625c5fe52c1385 Mon Sep 17 00:00:00 2001 From: piplongrun Date: Wed, 12 Feb 2020 23:59:18 +0100 Subject: [PATCH 2/2] Add etools engine to the list --- searx/settings.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/searx/settings.yml b/searx/settings.yml index ab3de395..08ff8dc6 100644 --- a/searx/settings.yml +++ b/searx/settings.yml @@ -202,6 +202,11 @@ engines: timeout: 3.0 disabled : True + - name : etools + engine : etools + shortcut : eto + disabled : True + - name : etymonline engine : xpath paging : True