apkmirror.py 1.4 KB

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