@@ -18,6 +18,11 @@ from babel.localedata import locale_identifiers
19from searx import network
19from searx import network
20from searx.utils import extract_text, eval_xpath, match_language
20from searx.utils import extract_text, eval_xpath, match_language
21+from searx.exceptions import (
22+ SearxEngineResponseException,
23+ SearxEngineCaptchaException,
@@ -54,6 +59,13 @@ sc_code_ts = 0
54sc_code = ''
59sc_code = ''
62+def raise_captcha(resp):
64+ if str(resp.url).startswith('https://www.startpage.com/sp/captcha'):
65+ # suspend CAPTCHA for 7 days
66+ raise SearxEngineCaptchaException(suspended_time=7 * 24 * 3600)
57def get_sc_code(headers):
69def get_sc_code(headers):
58 """Get an actual `sc` argument from startpage's home page.
70 """Get an actual `sc` argument from startpage's home page.
@@ -73,10 +85,17 @@ def get_sc_code(headers):
73 logger.debug("query new sc time-stamp ...")
85 logger.debug("query new sc time-stamp ...")
75 resp = network.get(base_url, headers=headers)
87 resp = network.get(base_url, headers=headers)
76 dom = html.fromstring(resp.text)
89 dom = html.fromstring(resp.text)
78− # href --> '/?sc=adrKJMgF8xwp20'
92+ # href --> '/?sc=adrKJMgF8xwp20'
79− href = eval_xpath(dom, '//a[@class="footer-home__logo"]')[0].get('href')
93+ href = eval_xpath(dom, '//a[@class="footer-home__logo"]')[0].get('href')
94+ except IndexError as exc:
95+ # suspend startpage API --> https://github.com/searxng/searxng/pull/695
96+ raise SearxEngineResponseException(
97+ suspended_time=7 * 24 * 3600, message="PR-695: query new sc time-stamp failed!"
81 sc_code = href[5:]
100 sc_code = href[5:]
82 sc_code_ts = time()
101 sc_code_ts = time()