2014-11-17 09:19:23 +00:00
|
|
|
# Startpage (Web)
|
|
|
|
#
|
2014-09-02 17:57:01 +00:00
|
|
|
# @website https://startpage.com
|
|
|
|
# @provide-api no (nothing found)
|
2014-11-17 09:19:23 +00:00
|
|
|
#
|
2014-09-02 17:57:01 +00:00
|
|
|
# @using-api no
|
|
|
|
# @results HTML
|
|
|
|
# @stable no (HTML can change)
|
|
|
|
# @parse url, title, content
|
|
|
|
#
|
|
|
|
# @todo paging
|
|
|
|
|
2013-10-19 16:29:39 +00:00
|
|
|
from lxml import html
|
2014-08-06 12:43:44 +00:00
|
|
|
from cgi import escape
|
2014-09-02 17:57:01 +00:00
|
|
|
import re
|
2015-02-06 16:31:10 +00:00
|
|
|
from searx.engines.xpath import extract_text
|
2014-09-02 17:57:01 +00:00
|
|
|
|
|
|
|
# engine dependent config
|
|
|
|
categories = ['general']
|
2014-11-17 09:19:23 +00:00
|
|
|
# there is a mechanism to block "bot" search
|
|
|
|
# (probably the parameter qid), require
|
|
|
|
# storing of qid's between mulitble search-calls
|
|
|
|
|
|
|
|
# paging = False
|
2014-09-02 17:57:01 +00:00
|
|
|
language_support = True
|
2013-10-19 16:29:39 +00:00
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# search-url
|
|
|
|
base_url = 'https://startpage.com/'
|
|
|
|
search_url = base_url + 'do/search'
|
2013-10-19 16:29:39 +00:00
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# specific xpath variables
|
|
|
|
# ads xpath //div[@id="results"]/div[@id="sponsored"]//div[@class="result"]
|
|
|
|
# not ads: div[@class="result"] are the direct childs of div[@id="results"]
|
|
|
|
results_xpath = '//div[@class="result"]'
|
|
|
|
link_xpath = './/h3/a'
|
2014-01-30 01:10:32 +00:00
|
|
|
|
2014-01-24 08:35:27 +00:00
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# do search-request
|
2013-10-19 16:29:39 +00:00
|
|
|
def request(query, params):
|
2014-09-02 17:57:01 +00:00
|
|
|
offset = (params['pageno'] - 1) * 10
|
|
|
|
|
2013-10-19 16:29:39 +00:00
|
|
|
params['url'] = search_url
|
|
|
|
params['method'] = 'POST'
|
2014-01-30 01:10:32 +00:00
|
|
|
params['data'] = {'query': query,
|
2014-11-17 09:19:23 +00:00
|
|
|
'startat': offset}
|
2014-09-02 17:57:01 +00:00
|
|
|
|
|
|
|
# set language if specified
|
|
|
|
if params['language'] != 'all':
|
2015-02-06 16:31:10 +00:00
|
|
|
params['data']['with_language'] = ('lang_' + params['language'].split('_')[0])
|
2014-09-02 17:57:01 +00:00
|
|
|
|
2013-10-19 16:29:39 +00:00
|
|
|
return params
|
|
|
|
|
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# get response from search-request
|
2013-10-19 16:29:39 +00:00
|
|
|
def response(resp):
|
|
|
|
results = []
|
2014-09-02 17:57:01 +00:00
|
|
|
|
2013-10-24 19:00:44 +00:00
|
|
|
dom = html.fromstring(resp.content)
|
2014-11-17 09:19:23 +00:00
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# parse results
|
|
|
|
for result in dom.xpath(results_xpath):
|
2014-11-17 09:19:23 +00:00
|
|
|
links = result.xpath(link_xpath)
|
|
|
|
if not links:
|
|
|
|
continue
|
|
|
|
link = links[0]
|
2013-10-24 21:43:39 +00:00
|
|
|
url = link.attrib.get('href')
|
2014-01-19 20:20:07 +00:00
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# block google-ad url's
|
2015-08-24 09:28:55 +00:00
|
|
|
if re.match("^http(s|)://(www\.)?google\.[a-z]+/aclk.*$", url):
|
|
|
|
continue
|
|
|
|
|
|
|
|
# block startpage search url's
|
|
|
|
if re.match("^http(s|)://(www\.)?startpage\.com/do/search\?.*$", url):
|
2014-09-02 17:57:01 +00:00
|
|
|
continue
|
|
|
|
|
2015-02-06 16:31:10 +00:00
|
|
|
title = escape(extract_text(link))
|
|
|
|
|
2014-02-11 12:13:51 +00:00
|
|
|
if result.xpath('./p[@class="desc"]'):
|
2015-02-06 16:31:10 +00:00
|
|
|
content = escape(extract_text(result.xpath('./p[@class="desc"]')))
|
2014-09-02 17:57:01 +00:00
|
|
|
else:
|
|
|
|
content = ''
|
2014-01-24 08:35:27 +00:00
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# append result
|
2014-11-17 09:19:23 +00:00
|
|
|
results.append({'url': url,
|
|
|
|
'title': title,
|
2014-09-02 17:57:01 +00:00
|
|
|
'content': content})
|
2014-01-24 08:35:27 +00:00
|
|
|
|
2014-09-02 17:57:01 +00:00
|
|
|
# return results
|
2013-10-19 16:29:39 +00:00
|
|
|
return results
|