svgrepo.py 1.2 KB

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