45 sxng_lang = params[
'searxng_locale'].split(
'-')[0]
46 netloc: str = traits.custom[
'wiki_netloc'].get(sxng_lang, main_wiki)
47 title: str = traits.custom[
'title'].get(sxng_lang,
'Special:Search')
48 base_url =
'https://' + netloc +
'/index.php?'
49 offset = (params[
'pageno'] - 1) * 20
51 if netloc == main_wiki:
52 eng_lang: str = traits.get_language(sxng_lang,
'English')
53 query +=
' (' + eng_lang +
')'
56 params[
'headers'][
'User-Agent'] =
"SearXNG"
57 elif netloc ==
'wiki.archlinuxcn.org':
58 base_url =
'https://' + netloc +
'/wzh/index.php?'
68 params[
'url'] = base_url + urlencode(args)
75 dom = lxml.html.fromstring(resp.text)
78 sxng_lang = resp.search_params[
'searxng_locale'].split(
'-')[0]
79 netloc: str = traits.custom[
'wiki_netloc'].get(sxng_lang, main_wiki)
80 base_url =
'https://' + netloc +
'/index.php?'
82 for result
in eval_xpath_list(dom,
'//ul[@class="mw-search-results"]/li'):
83 link = eval_xpath_getindex(result,
'.//div[@class="mw-search-result-heading"]/a', 0)
84 content = extract_text(result.xpath(
'.//div[@class="searchresult"]'))
87 'url': urljoin(base_url, link.get(
'href')),
88 'title': extract_text(link),
97 """Fetch languages from Archlinux-Wiki. The location of the Wiki address of a
98 language is mapped in a :py:obj:`custom field
99 <searx.enginelib.traits.EngineTraits.custom>` (``wiki_netloc``). Depending
100 on the location, the ``title`` argument in the request is translated.
106 "de": "wiki.archlinux.de",
108 "zh": "wiki.archlinuxcn.org"
111 "de": "Spezial:Suche",
113 "zh": "Special:\u641c\u7d22"
121 engine_traits.custom[
'wiki_netloc'] = {}
122 engine_traits.custom[
'title'] = {}
125 'de':
'Spezial:Suche',
131 resp = get(
'https://wiki.archlinux.org/')
133 print(
"ERROR: response from wiki.archlinux.org is not OK.")
135 dom = lxml.html.fromstring(resp.text)
136 for a
in eval_xpath_list(dom,
"//a[@class='interlanguage-link-target']"):
138 sxng_tag = language_tag(babel.Locale.parse(a.get(
'lang'), sep=
'-'))
140 sxng_tag = sxng_tag.split(
'_')[0]
142 netloc = urlparse(a.get(
'href')).netloc
143 if netloc !=
'wiki.archlinux.org':
144 title = title_map.get(sxng_tag)
146 print(
"ERROR: title tag from %s (%s) is unknown" % (netloc, sxng_tag))
148 engine_traits.custom[
'wiki_netloc'][sxng_tag] = netloc
149 engine_traits.custom[
'title'][sxng_tag] = title
151 eng_tag = extract_text(eval_xpath_list(a,
".//span"))
152 engine_traits.languages[sxng_tag] = eng_tag
154 engine_traits.languages[
'en'] =
'English'