on master help sign in
[remove] yandex engine
commit5d9db6c2f76b8ec1d13596be0d96f53035914977 authorAlexandre Flament <alex@al-f.net> dateThu 11 Feb 2021, 14:28 (6 years ago) parent436d366
2 files changed−77
searx/engines/yandex.py−72 searx/settings.yml−5
searx/engines/yandex.pydeleted−72
@@ -1,72 +0,0 @@
1−# SPDX-License-Identifier: AGPL-3.0-or-later
2−"""
3− Yahoo (Web)
4−"""
5−
6−from urllib.parse import urlencode, urlparse
7−from lxml import html
8−from searx import logger
9−from searx.exceptions import SearxEngineCaptchaException
10−
11−logger = logger.getChild('yandex engine')
12−
13−# about
14−about = {
15− "website": 'https://yandex.ru/',
16− "wikidata_id": 'Q5281',
17− "official_api_documentation": "?",
18− "use_official_api": False,
19− "require_api_key": False,
20− "results": 'HTML',
21−}
22−
23−# engine dependent config
24−categories = ['general']
25−paging = True
26−
27−default_tld = 'com'
28−language_map = {'ru': 'ru',
29− 'ua': 'ua',
30− 'be': 'by',
31− 'kk': 'kz',
32− 'tr': 'com.tr'}
33−
34−# search-url
35−base_url = 'https://yandex.{tld}/'
36−search_url = 'search/?{query}&p={page}'
37−
38−results_xpath = '//li[@class="serp-item"]'
39−url_xpath = './/h2/a/@href'
40−title_xpath = './/h2/a//text()'
41−content_xpath = './/div[@class="text-container typo typo_text_m typo_line_m organic__text"]//text()'
42−
43−
44−def request(query, params):
45− lang = params['language'].split('-')[0]
46− host = base_url.format(tld=language_map.get(lang) or default_tld)
47− params['url'] = host + search_url.format(page=params['pageno'] - 1,
48− query=urlencode({'text': query}))
49− return params
50−
51−
52−# get response from search-request
53−def response(resp):
54− resp_url = urlparse(resp.url)
55− if resp_url.path.startswith('/showcaptcha'):
56− raise SearxEngineCaptchaException()
57−
58− dom = html.fromstring(resp.text)
59− results = []
60−
61− for result in dom.xpath(results_xpath):
62− try:
63− res = {'url': result.xpath(url_xpath)[0],
64− 'title': ''.join(result.xpath(title_xpath)),
65− 'content': ''.join(result.xpath(content_xpath))}
66− except:
67− logger.exception('yandex parse crash')
68− continue
69−
70− results.append(res)
71−
72− return results
searx/settings.yml−5
@@ -1005,11 +1005,6 @@ engines:
10051005 shortcut : yh
10061006 disabled : True
10071007
1008− - name : yandex
1009− engine : yandex
1010− shortcut : yn
1011− disabled : True
1012−
10131008 - name : yahoo news
10141009 engine : yahoo_news
10151010 shortcut : yhn