apkmirror.py 1.6 KB

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