summaryrefslogtreecommitdiff
path: root/searx/engines
diff options
context:
space:
mode:
authorYaksh Bariya <yakshbari4@gmail.com>2024-02-27 17:47:20 +0530
committerMarkus Heiser <markus.heiser@darmarIT.de>2024-03-03 17:07:29 +0100
commitb1431e1670771481961a9e7cf6816d30f6afcfaa (patch)
tree139b8f2614c2ca2bf4c9b80a2e3023eb1d72f9c6 /searx/engines
parent1a66bfa66c5dd1e1fcfceee5703700b8e6e00424 (diff)
downloadsearxng-b1431e1670771481961a9e7cf6816d30f6afcfaa.tar.gz
searxng-b1431e1670771481961a9e7cf6816d30f6afcfaa.zip
[feat] engine: implementation of cppreference
Diffstat (limited to 'searx/engines')
-rw-r--r--searx/engines/cppreference.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/searx/engines/cppreference.py b/searx/engines/cppreference.py
new file mode 100644
index 000000000..b13cf730b
--- /dev/null
+++ b/searx/engines/cppreference.py
@@ -0,0 +1,39 @@
+# SPDX-License-Identifier: AGPL-3.0-or-later
+# lint: pylint
+"""Cppreference
+"""
+from lxml import html
+from searx.utils import eval_xpath
+
+
+about = {
+ "website": "https://en.cppreference.com/",
+ "wikidata_id": None,
+ "official_api_documentation": None,
+ "use_official_api": False,
+ "require_api_key": False,
+ "results": 'HTML',
+}
+
+
+categories = ['it']
+url = 'https://en.cppreference.com/'
+search_url = url + 'mwiki/index.php?title=Special%3ASearch&search={query}'
+
+
+def request(query, params):
+ params['url'] = search_url.format(query=query)
+ return query
+
+
+def response(resp):
+ results = []
+ dom = html.fromstring(resp.text)
+ for result in eval_xpath(dom, '//div[contains(@class, "mw-search-result-heading")]'):
+ results.append(
+ {
+ 'url': url + eval_xpath(result, './/a/@href')[0],
+ 'title': eval_xpath(result, './/a/text()')[0],
+ }
+ )
+ return results