searxng/searx/engines/cppreference.py
Markus Heiser 81cbe0befe
[upd] pypi: Bump black from 24.3.0 to 25.9.0 (#5251)
In 25.1.0 [2] an old bug has been fixed: "Docstring formatting does not apply to
module docstrings" [3].

[1] https://github.com/psf/black/blob/main/CHANGES.md#2590
[2] https://github.com/psf/black/blob/main/CHANGES.md#2510
[3] https://github.com/psf/black/issues/4094

Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
2025-09-26 12:35:57 +02:00

38 lines
939 B
Python

# SPDX-License-Identifier: AGPL-3.0-or-later
"""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