.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
searx.engines.dictzone Namespace Reference

Functions

 request (query, params)
 _clean_up_node (node)
EngineResults response (resp)

Variables

dict about
str engine_type = 'online_dictionary'
list categories = ['general', 'translate']
str base_url = "https://dictzone.com"
int weight = 100

Detailed Description

 Dictzone

Function Documentation

◆ _clean_up_node()

searx.engines.dictzone._clean_up_node ( node)
protected

Definition at line 39 of file dictzone.py.

39def _clean_up_node(node):
40 for x in ["./i", "./span", "./button"]:
41 for n in node.xpath(x):
42 n.getparent().remove(n)
43
44

Referenced by response().

Here is the caller graph for this function:

◆ request()

searx.engines.dictzone.request ( query,
params )

Definition at line 29 of file dictzone.py.

29def request(query, params): # pylint: disable=unused-argument
30
31 from_lang = params["from_lang"][2] # "english"
32 to_lang = params["to_lang"][2] # "german"
33 query = params["query"]
34
35 params["url"] = f"{base_url}/{from_lang}-{to_lang}-dictionary/{urllib.parse.quote_plus(query)}"
36 return params
37
38

◆ response()

EngineResults searx.engines.dictzone.response ( resp)

Definition at line 45 of file dictzone.py.

45def response(resp) -> EngineResults:
46 results = EngineResults()
47
48 item_list = []
49
50 if not resp.ok:
51 return results
52
53 dom = html.fromstring(resp.text)
54
55 for result in eval_xpath(dom, ".//table[@id='r']//tr"):
56
57 # each row is an Translations.Item
58
59 td_list = result.xpath("./td")
60 if len(td_list) != 2:
61 # ignore header columns "tr/th"
62 continue
63
64 col_from, col_to = td_list
65 _clean_up_node(col_from)
66
67 text = f"{extract_text(col_from)}"
68
69 synonyms = []
70 p_list = col_to.xpath(".//p")
71
72 for i, p_item in enumerate(p_list):
73
74 smpl: str = extract_text(p_list[i].xpath("./i[@class='smpl']")) # type: ignore
75 _clean_up_node(p_item)
76 p_text: str = extract_text(p_item) # type: ignore
77
78 if smpl:
79 p_text += " // " + smpl
80
81 if i == 0:
82 text += f" : {p_text}"
83 continue
84
85 synonyms.append(p_text)
86
87 item = results.types.Translations.Item(text=text, synonyms=synonyms)
88 item_list.append(item)
89
90 # the "autotranslate" of dictzone is loaded by the JS from URL:
91 # https://dictzone.com/trans/hello%20world/en_de
92
93 from_lang = resp.search_params["from_lang"][1] # "en"
94 to_lang = resp.search_params["to_lang"][1] # "de"
95 query = resp.search_params["query"]
96
97 # works only sometimes?
98 autotranslate = http_get(f"{base_url}/trans/{query}/{from_lang}_{to_lang}", timeout=1.0)
99 if autotranslate.ok and autotranslate.text:
100 item_list.insert(0, results.types.Translations.Item(text=autotranslate.text))
101
102 if item_list:
103 results.add(results.types.Translations(translations=item_list, url=resp.search_params["url"]))
104 return results

References _clean_up_node().

Here is the call graph for this function:

Variable Documentation

◆ about

dict searx.engines.dictzone.about
Initial value:
1= {
2 "website": 'https://dictzone.com/',
3 "wikidata_id": None,
4 "official_api_documentation": None,
5 "use_official_api": False,
6 "require_api_key": False,
7 "results": 'HTML',
8}

Definition at line 14 of file dictzone.py.

◆ base_url

str searx.engines.dictzone.base_url = "https://dictzone.com"

Definition at line 25 of file dictzone.py.

◆ categories

list searx.engines.dictzone.categories = ['general', 'translate']

Definition at line 24 of file dictzone.py.

◆ engine_type

str searx.engines.dictzone.engine_type = 'online_dictionary'

Definition at line 23 of file dictzone.py.

◆ weight

int searx.engines.dictzone.weight = 100

Definition at line 26 of file dictzone.py.