summaryrefslogtreecommitdiff
path: root/searx/engines/gigablast.py
blob: b852de9ba65e6150e92f7834913f65becc6cf79b (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
54
55
56
57
58
59
60
61
62
63
64
65
"""
 Gigablast (Web)

 @website     http://gigablast.com
 @provide-api yes (http://gigablast.com/api.html)

 @using-api   yes
 @results     XML
 @stable      yes
 @parse       url, title, content
"""

from urllib import urlencode
from cgi import escape
from lxml import etree

# engine dependent config
categories = ['general']
paging = True
number_of_results = 5

# search-url, invalid HTTPS certificate
base_url = 'http://gigablast.com/'
search_string = 'search?{query}&n={number_of_results}&s={offset}&xml=1&qh=0'

# specific xpath variables
results_xpath = '//response//result'
url_xpath = './/url'
title_xpath = './/title'
content_xpath = './/sum'


# do search-request
def request(query, params):
    offset = (params['pageno'] - 1) * number_of_results

    search_path = search_string.format(
        query=urlencode({'q': query}),
        offset=offset,
        number_of_results=number_of_results)

    params['url'] = base_url + search_path

    return params


# get response from search-request
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)

        # append result
        results.append({'url': url,
                        'title': title,
                        'content': content})

    # return results
    return results