| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 | 
""" Dictzone"""from urllib.parse import urljoinfrom lxml import htmlfrom searx.utils import eval_xpathabout = {    "website": 'https://dictzone.com/',    "wikidata_id": None,    "official_api_documentation": None,    "use_official_api": False,    "require_api_key": False,    "results": 'HTML',}engine_type = 'online_dictionnary'categories = ['general']url = 'https://dictzone.com/{from_lang}-{to_lang}-dictionary/{query}'weight = 100results_xpath = './/table[@id="r"]/tr'https_support = Truedef request(query, params):    params['url'] = url.format(from_lang=params['from_lang'][2],                               to_lang=params['to_lang'][2],                               query=params['query'])    return paramsdef response(resp):    results = []    dom = html.fromstring(resp.text)    for k, result in enumerate(eval_xpath(dom, results_xpath)[1:]):        try:            from_result, to_results_raw = eval_xpath(result, './td')        except:            continue        to_results = []        for to_result in eval_xpath(to_results_raw, './p/a'):            t = to_result.text_content()            if t.strip():                to_results.append(to_result.text_content())        results.append({            'url': urljoin(str(resp.url), '?%d' % k),            'title': from_result.text_content(),            'content': '; '.join(to_results)        })    return results
 |