2015-05-02 15:45:17 +02:00
|
|
|
"""
|
|
|
|
Gigablast (Web)
|
|
|
|
|
2015-12-22 20:25:57 +01:00
|
|
|
@website https://gigablast.com
|
|
|
|
@provide-api yes (https://gigablast.com/api.html)
|
2015-05-02 15:45:17 +02:00
|
|
|
|
|
|
|
@using-api yes
|
|
|
|
@results XML
|
|
|
|
@stable yes
|
|
|
|
@parse url, title, content
|
|
|
|
"""
|
2015-02-08 14:12:14 +01:00
|
|
|
|
|
|
|
from urllib import urlencode
|
|
|
|
from cgi import escape
|
|
|
|
from lxml import etree
|
2015-10-16 12:05:50 +02:00
|
|
|
from random import randint
|
|
|
|
from time import time
|
2015-02-08 14:12:14 +01:00
|
|
|
|
|
|
|
# engine dependent config
|
|
|
|
categories = ['general']
|
|
|
|
paging = True
|
|
|
|
number_of_results = 5
|
|
|
|
|
2015-05-02 11:43:12 +02:00
|
|
|
# search-url, invalid HTTPS certificate
|
2015-12-22 20:25:57 +01:00
|
|
|
base_url = 'https://gigablast.com/'
|
|
|
|
search_string = 'search?{query}&n={number_of_results}&s={offset}&format=xml&qh=0&rxiyd={rxiyd}&rand={rand}'
|
2015-02-08 14:12:14 +01:00
|
|
|
|
|
|
|
# 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,
|
2015-10-16 12:05:50 +02:00
|
|
|
number_of_results=number_of_results,
|
2015-12-22 20:25:57 +01:00
|
|
|
rxiyd=randint(10000, 10000000),
|
2015-10-16 12:05:50 +02:00
|
|
|
rand=int(time()))
|
2015-02-08 14:12:14 +01:00
|
|
|
|
|
|
|
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
|