on master help sign in
Merge pull request #2564 from dalf/fix-seznam

[fix] fix seznam engine

commit2b60d0d243f5f5848c44ffc4d8503ee974fc614b authorAlexandre Flament <alex@al-f.net> dateFri 12 Feb 2021, 10:56 (6 years ago) parent7e8381835dd069
2 files changed+65−17
searx/engines/seznam.py+64 searx/settings.yml+1−17
searx/engines/seznam.pynew file+64
@@ -0,0 +1,64 @@
1+# SPDX-License-Identifier: AGPL-3.0-or-later
2+"""
3+ Seznam
4+"""
5+
6+from urllib.parse import urlencode, urlparse
7+from lxml import html
8+from searx.poolrequests import get
9+from searx.exceptions import SearxEngineAccessDeniedException
10+from searx.utils import extract_text, eval_xpath_list, eval_xpath_getindex
11+
12+# about
13+about = {
14+ "website": "https://www.seznam.cz/",
15+ "wikidata_id": "Q3490485",
16+ "official_api_documentation": "https://api.sklik.cz/",
17+ "use_official_api": False,
18+ "require_api_key": False,
19+ "results": "HTML",
20+}
21+
22+base_url = 'https://search.seznam.cz/'
23+
24+
25+def request(query, params):
26+ response_index = get(base_url, headers=params['headers'], raise_for_httperror=True)
27+ dom = html.fromstring(response_index.text)
28+
29+ url_params = {'q': query}
30+ for e in eval_xpath_list(dom, '//input[@type="hidden"]'):
31+ name = e.get('name')
32+ value = e.get('value')
33+ url_params[name] = value
34+
35+ params['url'] = base_url + '?' + urlencode(url_params)
36+ params['cookies'] = response_index.cookies
37+ return params
38+
39+
40+def response(resp):
41+ resp_url = urlparse(resp.url)
42+ if resp_url.path.startswith('/verify'):
43+ raise SearxEngineAccessDeniedException()
44+
45+ results = []
46+
47+ dom = html.fromstring(resp.content.decode())
48+ for result_element in eval_xpath_list(dom, '//div[@id="searchpage-root"]//div[@data-dot="results"]/div'):
49+ dot_data = eval_xpath_getindex(result_element, './div/div[@data-dot-data]/@data-dot-data', 0, default=None)
50+ if dot_data is None:
51+ title_element = eval_xpath_getindex(result_element, './/h3/a', 0)
52+ results.append({
53+ 'url': title_element.get('href'),
54+ 'title': extract_text(title_element),
55+ 'content': extract_text(eval_xpath_getindex(title_element, '../../div[2]', 0)),
56+ })
57+ elif dot_data == '{"reporter_name":"hint/related/relates"}':
58+ suggestions_element = eval_xpath_getindex(result_element,
59+ './div/div[@data-dot="main-box"]', 0, default=None)
60+ if suggestions_element is not None:
61+ for suggestion in eval_xpath_list(suggestions_element, './/ul/li'):
62+ results.append({'suggestion': extract_text(suggestion)})
63+
64+ return results
searx/settings.yml+1−17
@@ -1170,24 +1170,8 @@ engines:
11701170
11711171 - name : seznam
11721172 shortcut: szn
1173− engine: xpath
1174− paging : True
1175− search_url : https://search.seznam.cz/?q={query}&count=10&from={pageno}
1176− results_xpath: //div[@class="Page-content"]//div[contains(@class, "Result ")]
1177− url_xpath : ./h3/a/@href
1178− title_xpath : ./h3
1179− content_xpath : .//p[@class="Result-description"]
1180− suggestion_xpath: //div[@class="Related-container"]//div[@class="RelatedItem"]/div/span/a
1181− first_page_num : 0
1182− page_size : 10
1173+ engine: seznam
11831174 disabled : True
1184− about:
1185− website: https://www.seznam.cz/
1186− wikidata_id: Q3490485
1187− official_api_documentation: https://api.sklik.cz/
1188− use_official_api: false
1189− require_api_key: false
1190− results: HTML
11911175
11921176 - name : mojeek
11931177 shortcut: mjk