diff options
author | Bnyro <bnyro@tutanota.com> | 2024-03-06 10:22:49 +0100 |
---|---|---|
committer | Markus Heiser <markus.heiser@darmarIT.de> | 2024-03-09 10:17:16 +0100 |
commit | 6dd07b88a4b8fce0f98d9274decb95541cebc915 (patch) | |
tree | 598cc7b1d40d8cc377f2c05c61494d578e6a2acb /searx/engines/lib_rs.py | |
parent | 50d5a9ff60e16324ffa68b9a37ca87a7de81c450 (diff) | |
download | searxng-6dd07b88a4b8fce0f98d9274decb95541cebc915.tar.gz searxng-6dd07b88a4b8fce0f98d9274decb95541cebc915.zip |
[feat] lib.rs: use packages.html template
Diffstat (limited to 'searx/engines/lib_rs.py')
-rw-r--r-- | searx/engines/lib_rs.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/searx/engines/lib_rs.py b/searx/engines/lib_rs.py new file mode 100644 index 000000000..c9435cc2a --- /dev/null +++ b/searx/engines/lib_rs.py @@ -0,0 +1,56 @@ +# SPDX-License-Identifier: AGPL-3.0-or-later +# lint: pylint +"""lib.rs (packages)""" + +from urllib.parse import quote_plus +from lxml import html +from searx.utils import eval_xpath, eval_xpath_list, extract_text + +about = { + 'website': 'https://lib.rs', + 'wikidata_id': 'Q113486010', + 'use_official_api': False, + 'require_api_key': False, + 'results': "HTML", +} + +categories = ["it", "packages"] + +base_url = 'https://lib.rs' + +results_xpath = '/html/body/main/div/ol/li/a' +url_xpath = './@href' +title_xpath = './div[@class="h"]/h4' +content_xpath = './div[@class="h"]/p' +version_xpath = './div[@class="meta"]/span[contains(@class, "version")]' +download_count_xpath = './div[@class="meta"]/span[@class="downloads"]' +tags_xpath = './div[@class="meta"]/span[contains(@class, "k")]/text()' + + +def request(query, params): + params['url'] = f"{base_url}/search?q={quote_plus(query)}" + + return params + + +def response(resp): + results = [] + + doc = html.fromstring(resp.text) + + for result in eval_xpath_list(doc, results_xpath): + package_name = extract_text(eval_xpath(result, title_xpath)) + results.append( + { + 'template': 'packages.html', + 'title': package_name, + 'url': base_url + extract_text(eval_xpath(result, url_xpath)), # type: ignore + 'content': extract_text(eval_xpath(result, content_xpath)), + 'package_name': package_name, + 'version': extract_text(eval_xpath(result, version_xpath)), + 'popularity': extract_text(eval_xpath(result, download_count_xpath)), + 'tags': eval_xpath_list(result, tags_xpath), + } + ) + + return results |