svgrepo.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """Svgrepo (images)
  3. """
  4. from lxml import html
  5. from searx.utils import extract_text, eval_xpath, eval_xpath_list
  6. about = {
  7. "website": 'https://www.svgrepo.com',
  8. "official_api_documentation": 'https://svgapi.com',
  9. "use_official_api": False,
  10. "require_api_key": False,
  11. "results": 'HTML',
  12. }
  13. paging = True
  14. categories = ['images']
  15. base_url = "https://www.svgrepo.com"
  16. results_xpath = "//div[@class='style_nodeListing__7Nmro']/div"
  17. url_xpath = ".//a/@href"
  18. title_xpath = ".//a/@title"
  19. img_src_xpath = ".//img/@src"
  20. def request(query, params):
  21. params['url'] = f"{base_url}/vectors/{query}/{params['pageno']}/"
  22. return params
  23. def response(resp):
  24. results = []
  25. dom = html.fromstring(resp.text)
  26. for result in eval_xpath_list(dom, results_xpath):
  27. results.append(
  28. {
  29. 'template': 'images.html',
  30. 'url': base_url + extract_text(eval_xpath(result, url_xpath)),
  31. 'title': extract_text(eval_xpath(result, title_xpath)).replace(" SVG File", "").replace("Show ", ""),
  32. 'img_src': extract_text(eval_xpath(result, img_src_xpath)),
  33. }
  34. )
  35. return results