apkmirror.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. # lint: pylint
  3. """APKMirror
  4. """
  5. # pylint: disable=invalid-name, missing-function-docstring
  6. from urllib.parse import urlencode
  7. from lxml import html
  8. from searx import logger
  9. from searx.utils import (
  10. eval_xpath_list,
  11. eval_xpath_getindex,
  12. extract_text,
  13. )
  14. logger = logger.getChild('APKMirror engine')
  15. about = {
  16. "website": 'https://www.apkmirror.com',
  17. "wikidata_id": None,
  18. "official_api_documentation": None,
  19. "use_official_api": False,
  20. "require_api_key": False,
  21. "results": 'HTML',
  22. }
  23. # engine dependent config
  24. categories = ['files']
  25. paging = True
  26. time_range_support = False
  27. # search-url
  28. base_url = 'https://www.apkmirror.com'
  29. search_url = base_url + '/?post_type=app_release&searchtype=apk&page={pageno}&{query}'
  30. def request(query, params):
  31. params['url'] = search_url.format(
  32. pageno = params['pageno'],
  33. query = urlencode({'s': query}),
  34. )
  35. logger.debug("query_url --> %s", params['url'])
  36. return params
  37. def response(resp):
  38. results = []
  39. dom = html.fromstring(resp.text)
  40. # parse results
  41. for result in eval_xpath_list(dom, "//div[@id='content']//div[@class='listWidget']/div/div[@class='appRow']"):
  42. link = eval_xpath_getindex(result, './/h5/a', 0)
  43. url = base_url + link.attrib.get('href') + '#downloads'
  44. title = extract_text(link)
  45. img_src = base_url + eval_xpath_getindex(result, './/img/@src', 0)
  46. res = {
  47. 'url': url,
  48. 'title': title,
  49. 'img_src': img_src
  50. }
  51. results.append(res)
  52. return results