2021-01-13 10:31:25 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
2016-09-06 14:36:04 +00:00
|
|
|
"""
|
|
|
|
Dictzone
|
|
|
|
"""
|
|
|
|
|
2020-08-06 15:42:46 +00:00
|
|
|
from urllib.parse import urljoin
|
2016-09-06 09:47:27 +00:00
|
|
|
from lxml import html
|
2020-12-16 15:20:03 +00:00
|
|
|
from searx.utils import eval_xpath
|
2016-09-06 09:47:27 +00:00
|
|
|
|
2021-01-13 10:31:25 +00:00
|
|
|
# about
|
|
|
|
about = {
|
|
|
|
"website": 'https://dictzone.com/',
|
|
|
|
"wikidata_id": None,
|
|
|
|
"official_api_documentation": None,
|
|
|
|
"use_official_api": False,
|
|
|
|
"require_api_key": False,
|
|
|
|
"results": 'HTML',
|
|
|
|
}
|
2020-12-16 15:20:03 +00:00
|
|
|
|
2021-06-03 16:02:47 +00:00
|
|
|
engine_type = 'online_dictionary'
|
2024-04-25 17:48:37 +00:00
|
|
|
categories = ['general', 'translate']
|
2020-08-06 15:42:46 +00:00
|
|
|
url = 'https://dictzone.com/{from_lang}-{to_lang}-dictionary/{query}'
|
2016-09-06 09:47:27 +00:00
|
|
|
weight = 100
|
|
|
|
|
|
|
|
results_xpath = './/table[@id="r"]/tr'
|
2020-12-09 16:33:18 +00:00
|
|
|
https_support = True
|
2016-09-06 09:47:27 +00:00
|
|
|
|
|
|
|
|
2024-03-11 06:45:08 +00:00
|
|
|
def request(query, params): # pylint: disable=unused-argument
|
2021-12-27 08:26:22 +00:00
|
|
|
params['url'] = url.format(from_lang=params['from_lang'][2], to_lang=params['to_lang'][2], query=params['query'])
|
2016-09-06 09:47:27 +00:00
|
|
|
|
|
|
|
return params
|
|
|
|
|
2016-09-06 12:24:08 +00:00
|
|
|
|
2016-09-06 09:47:27 +00:00
|
|
|
def response(resp):
|
|
|
|
results = []
|
|
|
|
|
|
|
|
dom = html.fromstring(resp.text)
|
|
|
|
|
2019-11-15 08:31:37 +00:00
|
|
|
for k, result in enumerate(eval_xpath(dom, results_xpath)[1:]):
|
2016-09-06 09:47:27 +00:00
|
|
|
try:
|
2019-11-15 08:31:37 +00:00
|
|
|
from_result, to_results_raw = eval_xpath(result, './td')
|
2024-03-11 06:45:08 +00:00
|
|
|
except: # pylint: disable=bare-except
|
2016-09-06 09:47:27 +00:00
|
|
|
continue
|
|
|
|
|
|
|
|
to_results = []
|
2019-11-15 08:31:37 +00:00
|
|
|
for to_result in eval_xpath(to_results_raw, './p/a'):
|
2016-09-06 09:47:27 +00:00
|
|
|
t = to_result.text_content()
|
|
|
|
if t.strip():
|
|
|
|
to_results.append(to_result.text_content())
|
|
|
|
|
2021-12-27 08:26:22 +00:00
|
|
|
results.append(
|
|
|
|
{
|
|
|
|
'url': urljoin(str(resp.url), '?%d' % k),
|
|
|
|
'title': from_result.text_content(),
|
|
|
|
'content': '; '.join(to_results),
|
|
|
|
}
|
|
|
|
)
|
2016-09-06 09:47:27 +00:00
|
|
|
|
|
|
|
return results
|