37 sxng_lang = params[
'searxng_locale'].split(
'-')[0]
38 netloc: str = traits.custom[
'wiki_netloc'].get(sxng_lang, main_wiki)
39 title: str = traits.custom[
'title'].get(sxng_lang,
'Special:Search')
40 base_url =
'https://' + netloc +
'/index.php?'
41 offset = (params[
'pageno'] - 1) * 20
43 if netloc == main_wiki:
44 eng_lang: str = traits.get_language(sxng_lang,
'English')
45 query +=
' (' + eng_lang +
')'
48 params[
'headers'][
'User-Agent'] =
"SearXNG"
49 elif netloc ==
'wiki.archlinuxcn.org':
50 base_url =
'https://' + netloc +
'/wzh/index.php?'
60 params[
'url'] = base_url + urlencode(args)
67 dom = lxml.html.fromstring(resp.text)
70 sxng_lang = resp.search_params[
'searxng_locale'].split(
'-')[0]
71 netloc: str = traits.custom[
'wiki_netloc'].get(sxng_lang, main_wiki)
72 base_url =
'https://' + netloc +
'/index.php?'
74 for result
in eval_xpath_list(dom,
'//ul[@class="mw-search-results"]/li'):
75 link = eval_xpath_getindex(result,
'.//div[@class="mw-search-result-heading"]/a', 0)
76 content = extract_text(result.xpath(
'.//div[@class="searchresult"]'))
79 'url': urljoin(base_url, link.get(
'href')),
80 'title': extract_text(link),
89 """Fetch languages from Archlinux-Wiki. The location of the Wiki address of a
90 language is mapped in a :py:obj:`custom field
91 <searx.enginelib.traits.EngineTraits.custom>` (``wiki_netloc``). Depending
92 on the location, the ``title`` argument in the request is translated.
98 "de": "wiki.archlinux.de",
100 "zh": "wiki.archlinuxcn.org"
103 "de": "Spezial:Suche",
105 "zh": "Special:\u641c\u7d22"
113 engine_traits.custom[
'wiki_netloc'] = {}
114 engine_traits.custom[
'title'] = {}
117 'de':
'Spezial:Suche',
123 resp = get(
'https://wiki.archlinux.org/')
125 print(
"ERROR: response from wiki.archlinux.org is not OK.")
127 dom = lxml.html.fromstring(resp.text)
128 for a
in eval_xpath_list(dom,
"//a[@class='interlanguage-link-target']"):
130 sxng_tag = language_tag(babel.Locale.parse(a.get(
'lang'), sep=
'-'))
132 sxng_tag = sxng_tag.split(
'_')[0]
134 netloc = urlparse(a.get(
'href')).netloc
135 if netloc !=
'wiki.archlinux.org':
136 title = title_map.get(sxng_tag)
138 print(
"ERROR: title tag from %s (%s) is unknown" % (netloc, sxng_tag))
140 engine_traits.custom[
'wiki_netloc'][sxng_tag] = netloc
141 engine_traits.custom[
'title'][sxng_tag] = title
143 eng_tag = extract_text(eval_xpath_list(a,
".//span"))
144 engine_traits.languages[sxng_tag] = eng_tag
146 engine_traits.languages[
'en'] =
'English'