.oO SearXNG Developer Documentation Oo.
Loading...
Searching...
No Matches
lib_rs.py
Go to the documentation of this file.
1# SPDX-License-Identifier: AGPL-3.0-or-later
2"""lib.rs (packages)"""
3
4from urllib.parse import quote_plus
5from lxml import html
6from searx.utils import eval_xpath, eval_xpath_list, extract_text
7
8about = {
9 'website': 'https://lib.rs',
10 'wikidata_id': 'Q113486010',
11 'use_official_api': False,
12 'require_api_key': False,
13 'results': "HTML",
14}
15
16categories = ["it", "packages"]
17
18base_url = 'https://lib.rs'
19
20results_xpath = '/html/body/main/div/ol/li/a'
21url_xpath = './@href'
22title_xpath = './div[@class="h"]/h4'
23content_xpath = './div[@class="h"]/p'
24version_xpath = './div[@class="meta"]/span[contains(@class, "version")]'
25download_count_xpath = './div[@class="meta"]/span[@class="downloads"]'
26tags_xpath = './div[@class="meta"]/span[contains(@class, "k")]/text()'
27
28
29def request(query, params):
30 params['url'] = f"{base_url}/search?q={quote_plus(query)}"
31
32 return params
33
34
35def response(resp):
36 results = []
37
38 doc = html.fromstring(resp.text)
39
40 for result in eval_xpath_list(doc, results_xpath):
41 package_name = extract_text(eval_xpath(result, title_xpath))
42 results.append(
43 {
44 'template': 'packages.html',
45 'title': package_name,
46 'url': base_url + extract_text(eval_xpath(result, url_xpath)), # type: ignore
47 'content': extract_text(eval_xpath(result, content_xpath)),
48 'package_name': package_name,
49 'version': extract_text(eval_xpath(result, version_xpath)),
50 'popularity': extract_text(eval_xpath(result, download_count_xpath)),
51 'tags': eval_xpath_list(result, tags_xpath),
52 }
53 )
54
55 return results
request(query, params)
Definition lib_rs.py:29