@@ -1,8 +1,8 @@
1−## Startpage (Web)
2−#
1+# Startpage (Web)
2+#
33# @website https://startpage.com
44# @provide-api no (nothing found)
5−#
5+#
66# @using-api no
77# @results HTML
88# @stable no (HTML can change)
@@ -17,8 +17,11 @@ import re
1717
1818# engine dependent config
1919categories = ['general']
20−# there is a mechanism to block "bot" search (probably the parameter qid), require storing of qid's between mulitble search-calls
21−#paging = False
20+# there is a mechanism to block "bot" search
21+# (probably the parameter qid), require
22+# storing of qid's between mulitble search-calls
23+
24+# paging = False
2225language_support = True
2326
2427# search-url
@@ -40,11 +43,12 @@ def request(query, params):
4043 params['url'] = search_url
4144 params['method'] = 'POST'
4245 params['data'] = {'query': query,
43− 'startat': offset}
46+ 'startat': offset}
4447
4548 # set language if specified
4649 if params['language'] != 'all':
47− params['data']['with_language'] = 'lang_' + params['language'].split('_')[0]
50+ params['data']['with_language'] = ('lang_' +
51+ params['language'].split('_')[0])
4852
4953 return params
5054
@@ -54,10 +58,13 @@ def response(resp):
5458 results = []
5559
5660 dom = html.fromstring(resp.content)
57−
61+
5862 # parse results
5963 for result in dom.xpath(results_xpath):
60− link = result.xpath(link_xpath)[0]
64+ links = result.xpath(link_xpath)
65+ if not links:
66+ continue
67+ link = links[0]
6168 url = link.attrib.get('href')
6269 title = escape(link.text_content())
6370
@@ -66,13 +73,14 @@ def response(resp):
6673 continue
6774
6875 if result.xpath('./p[@class="desc"]'):
69− content = escape(result.xpath('./p[@class="desc"]')[0].text_content())
76+ content = escape(result.xpath('./p[@class="desc"]')[0]
77+ .text_content())
7078 else:
7179 content = ''
7280
7381 # append result
74− results.append({'url': url,
75− 'title': title,
82+ results.append({'url': url,
83+ 'title': title,
7684 'content': content})
7785
7886 # return results