on master help sign in
Merge pull request #2350 from dalf/mod-engines-report-captcha

[mod] stackoverflow & yandex: detect CAPTCHA response

commitcec73b5dcf6e94918798c6e1e6457dd021a34a39 authorAlexandre Flament <alex@al-f.net> dateThu 3 Dec 2020, 13:50 (6 years ago) parent7905d41fa909c7
2 files changed+12−2
searx/engines/stackoverflow.py+6−1 searx/engines/yandex.py+6−1
searx/engines/stackoverflow.py+6−1
@@ -10,9 +10,10 @@
1010 @parse url, title, content
1111"""
1212
13−from urllib.parse import urlencode, urljoin
13+from urllib.parse import urlencode, urljoin, urlparse
1414from lxml import html
1515from searx.utils import extract_text
16+from searx.exceptions import SearxEngineCaptchaException
1617
1718# engine dependent config
1819categories = ['it']
@@ -37,6 +38,10 @@ def request(query, params):
3738
3839# get response from search-request
3940def response(resp):
41+ resp_url = urlparse(resp.url)
42+ if resp_url.path.startswith('/nocaptcha'):
43+ raise SearxEngineCaptchaException()
44+
4045 results = []
4146
4247 dom = html.fromstring(resp.text)
searx/engines/yandex.py+6−1
@@ -9,9 +9,10 @@
99 @parse url, title, content
1010"""
1111
12−from urllib.parse import urlencode
12+from urllib.parse import urlencode, urlparse
1313from lxml import html
1414from searx import logger
15+from searx.exceptions import SearxEngineCaptchaException
1516
1617logger = logger.getChild('yandex engine')
1718
@@ -47,6 +48,10 @@ def request(query, params):
4748
4849# get response from search-request
4950def response(resp):
51+ resp_url = urlparse(resp.url)
52+ if resp_url.path.startswith('/showcaptcha'):
53+ raise SearxEngineCaptchaException()
54+
5055 dom = html.fromstring(resp.text)
5156 results = []
5257