summaryrefslogtreecommitdiff
path: root/searx/engines/etools.py
blob: a0762d1c73240e51c395cb56e1b31f2a019fa681 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
"""
 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 urllib.parse import quote
from searx.utils import extract_text, 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