.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
dictzone.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""
3 Dictzone
4"""
5
6from urllib.parse import urljoin
7from lxml import html
8from searx.utils import eval_xpath
9
10# about
11about = {
12 "website": 'https://dictzone.com/',
13 "wikidata_id": None,
14 "official_api_documentation": None,
15 "use_official_api": False,
16 "require_api_key": False,
17 "results": 'HTML',
18}
19
20engine_type = 'online_dictionary'
21categories = ['general', 'translate']
22url = 'https://dictzone.com/{from_lang}-{to_lang}-dictionary/{query}'
23weight = 100
24
25results_xpath = './/table[@id="r"]/tr'
26https_support = True
27
28
29def request(query, params): # pylint: disable=unused-argument
30 params['url'] = url.format(from_lang=params['from_lang'][2], to_lang=params['to_lang'][2], query=params['query'])
31
32 return params
33
34
35def response(resp):
36 results = []
37
38 dom = html.fromstring(resp.text)
39
40 for k, result in enumerate(eval_xpath(dom, results_xpath)[1:]):
41 try:
42 from_result, to_results_raw = eval_xpath(result, './td')
43 except: # pylint: disable=bare-except
44 continue
45
46 to_results = []
47 for to_result in eval_xpath(to_results_raw, './p/a'):
48 t = to_result.text_content()
49 if t.strip():
50 to_results.append(to_result.text_content())
51
52 results.append(
53 {
54 'url': urljoin(str(resp.url), '?%d' % k),
55 'title': from_result.text_content(),
56 'content': '; '.join(to_results),
57 }
58 )
59
60 return results
request(query, params)
Definition dictzone.py:29