emojipedia.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """Emojipedia
  4. Emojipedia is an emoji reference website which documents the meaning and
  5. common usage of emoji characters in the Unicode Standard. It is owned by Zedge
  6. since 2021. Emojipedia is a voting member of The Unicode Consortium.[1]
  7. [1] https://en.wikipedia.org/wiki/Emojipedia
  8. """
  9. from urllib.parse import urlencode
  10. from lxml import html
  11. from searx.utils import (
  12. eval_xpath_list,
  13. eval_xpath_getindex,
  14. extract_text,
  15. )
  16. about = {
  17. "website": 'https://emojipedia.org',
  18. "wikidata_id": 'Q22908129',
  19. "official_api_documentation": None,
  20. "use_official_api": False,
  21. "require_api_key": False,
  22. "results": 'HTML',
  23. }
  24. categories = []
  25. paging = False
  26. time_range_support = False
  27. base_url = 'https://emojipedia.org'
  28. search_url = base_url + '/search/?{query}'
  29. def request(query, params):
  30. params['url'] = search_url.format(
  31. query=urlencode({'q': query}),
  32. )
  33. return params
  34. def response(resp):
  35. results = []
  36. dom = html.fromstring(resp.text)
  37. for result in eval_xpath_list(dom, "//ol[@class='search-results']/li"):
  38. extracted_desc = extract_text(eval_xpath_getindex(result, './/p', 0))
  39. if 'No results found.' in extracted_desc:
  40. break
  41. link = eval_xpath_getindex(result, './/h2/a', 0)
  42. url = base_url + link.attrib.get('href')
  43. title = extract_text(link)
  44. content = extracted_desc
  45. res = {'url': url, 'title': title, 'content': content}
  46. results.append(res)
  47. return results