[fix] startpage engine compatibility

This commit is contained in:
Adam Tauber 2014-11-17 10:19:23 +01:00
parent 55234d96b7
commit b1234ee889
1 changed files with 20 additions and 12 deletions

View File

@ -1,8 +1,8 @@
## Startpage (Web) # Startpage (Web)
# #
# @website https://startpage.com # @website https://startpage.com
# @provide-api no (nothing found) # @provide-api no (nothing found)
# #
# @using-api no # @using-api no
# @results HTML # @results HTML
# @stable no (HTML can change) # @stable no (HTML can change)
@ -17,8 +17,11 @@ import re
# engine dependent config # engine dependent config
categories = ['general'] categories = ['general']
# there is a mechanism to block "bot" search (probably the parameter qid), require storing of qid's between mulitble search-calls # there is a mechanism to block "bot" search
#paging = False # (probably the parameter qid), require
# storing of qid's between mulitble search-calls
# paging = False
language_support = True language_support = True
# search-url # search-url
@ -40,11 +43,12 @@ def request(query, params):
params['url'] = search_url params['url'] = search_url
params['method'] = 'POST' params['method'] = 'POST'
params['data'] = {'query': query, params['data'] = {'query': query,
'startat': offset} 'startat': offset}
# set language if specified # set language if specified
if params['language'] != 'all': if params['language'] != 'all':
params['data']['with_language'] = 'lang_' + params['language'].split('_')[0] params['data']['with_language'] = ('lang_' +
params['language'].split('_')[0])
return params return params
@ -54,10 +58,13 @@ def response(resp):
results = [] results = []
dom = html.fromstring(resp.content) dom = html.fromstring(resp.content)
# parse results # parse results
for result in dom.xpath(results_xpath): for result in dom.xpath(results_xpath):
link = result.xpath(link_xpath)[0] links = result.xpath(link_xpath)
if not links:
continue
link = links[0]
url = link.attrib.get('href') url = link.attrib.get('href')
title = escape(link.text_content()) title = escape(link.text_content())
@ -66,13 +73,14 @@ def response(resp):
continue continue
if result.xpath('./p[@class="desc"]'): if result.xpath('./p[@class="desc"]'):
content = escape(result.xpath('./p[@class="desc"]')[0].text_content()) content = escape(result.xpath('./p[@class="desc"]')[0]
.text_content())
else: else:
content = '' content = ''
# append result # append result
results.append({'url': url, results.append({'url': url,
'title': title, 'title': title,
'content': content}) 'content': content})
# return results # return results