cppreference.py 940 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """Cppreference
  3. """
  4. from lxml import html
  5. from searx.utils import eval_xpath
  6. about = {
  7. "website": "https://en.cppreference.com/",
  8. "wikidata_id": None,
  9. "official_api_documentation": None,
  10. "use_official_api": False,
  11. "require_api_key": False,
  12. "results": 'HTML',
  13. }
  14. categories = ['it']
  15. url = 'https://en.cppreference.com/'
  16. search_url = url + 'mwiki/index.php?title=Special%3ASearch&search={query}'
  17. def request(query, params):
  18. params['url'] = search_url.format(query=query)
  19. return query
  20. def response(resp):
  21. results = []
  22. dom = html.fromstring(resp.text)
  23. for result in eval_xpath(dom, '//div[contains(@class, "mw-search-result-heading")]'):
  24. results.append(
  25. {
  26. 'url': url + eval_xpath(result, './/a/@href')[0],
  27. 'title': eval_xpath(result, './/a/text()')[0],
  28. }
  29. )
  30. return results