cppreference.py 955 B

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