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 +
')'
54 elif netloc ==
'wiki.archlinuxcn.org':
55 base_url =
'https://' + netloc +
'/wzh/index.php?'
65 params[
'url'] = base_url + urlencode(args)
72 dom = lxml.html.fromstring(resp.text)
75 sxng_lang = resp.search_params[
'searxng_locale'].split(
'-')[0]
76 netloc: str = traits.custom[
'wiki_netloc'].get(sxng_lang, main_wiki)
77 base_url =
'https://' + netloc +
'/index.php?'
79 for result
in eval_xpath_list(dom,
'//ul[@class="mw-search-results"]/li'):
80 link = eval_xpath_getindex(result,
'.//div[@class="mw-search-result-heading"]/a', 0)
81 content = extract_text(result.xpath(
'.//div[@class="searchresult"]'))
84 'url': urljoin(base_url, link.get(
'href')),
85 'title': extract_text(link),
94 """Fetch languages from Archlinux-Wiki. The location of the Wiki address of a
95 language is mapped in a :py:obj:`custom field
96 <searx.enginelib.traits.EngineTraits.custom>` (``wiki_netloc``). Depending
97 on the location, the ``title`` argument in the request is translated.
103 "de": "wiki.archlinux.de",
105 "zh": "wiki.archlinuxcn.org"
108 "de": "Spezial:Suche",
110 "zh": "Special:\u641c\u7d22"
118 engine_traits.custom[
'wiki_netloc'] = {}
119 engine_traits.custom[
'title'] = {}
122 'de':
'Spezial:Suche',
128 resp = get(
'https://wiki.archlinux.org/')
130 print(
"ERROR: response from wiki.archlinux.org is not OK.")
132 dom = lxml.html.fromstring(resp.text)
133 for a
in eval_xpath_list(dom,
"//a[@class='interlanguage-link-target']"):
135 sxng_tag = language_tag(babel.Locale.parse(a.get(
'lang'), sep=
'-'))
137 sxng_tag = sxng_tag.split(
'_')[0]
139 netloc = urlparse(a.get(
'href')).netloc
140 if netloc !=
'wiki.archlinux.org':
141 title = title_map.get(sxng_tag)
143 print(
"ERROR: title tag from %s (%s) is unknown" % (netloc, sxng_tag))
145 engine_traits.custom[
'wiki_netloc'][sxng_tag] = netloc
146 engine_traits.custom[
'title'][sxng_tag] = title
148 eng_tag = extract_text(eval_xpath_list(a,
".//span"))
149 engine_traits.languages[sxng_tag] = eng_tag
151 engine_traits.languages[
'en'] =
'English'