apkmirror.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # SPDX-License-Identifier: AGPL-3.0-or-later
  2. """
  3. APK Mirror
  4. """
  5. from urllib.parse import urlencode
  6. from lxml import html
  7. from searx.utils import extract_text, eval_xpath_list, eval_xpath_getindex
  8. # about
  9. about = {
  10. "website": 'https://www.apkmirror.com',
  11. "wikidata_id": None,
  12. "official_api_documentation": None,
  13. "use_official_api": False,
  14. "require_api_key": False,
  15. "results": 'HTML',
  16. }
  17. # engine dependent config
  18. categories = ['it']
  19. paging = True
  20. # I am not 100% certain about this, as apkmirror appears to be a wordpress site,
  21. # which might support time_range searching. If you want to implement it, go ahead.
  22. time_range_support = False
  23. # search-url
  24. base_url = 'https://www.apkmirror.com'
  25. search_url = base_url + '/?post_type=app_release&searchtype=apk&page={pageno}&{query}'
  26. # do search-request
  27. def request(query, params):
  28. params['url'] = search_url.format(pageno=params['pageno'],
  29. query=urlencode({'s': query}))
  30. return params
  31. # get response from search-request
  32. def response(resp):
  33. results = []
  34. dom = html.fromstring(resp.text)
  35. # parse results
  36. for result in eval_xpath_list(dom, './/div[@id="content"]/div[@class="listWidget"]//div[@class="appRow"]'):
  37. link = eval_xpath_getindex(result, './/h5/a', 0)
  38. url = base_url + link.attrib.get('href') + '#downloads'
  39. title = extract_text(link)
  40. thumbnail_src = base_url\
  41. + eval_xpath_getindex(result, './/img', 0).attrib.get('src').replace('&w=32&h=32', '&w=64&h=64')
  42. res = {
  43. 'url': url,
  44. 'title': title,
  45. 'thumbnail_src': thumbnail_src
  46. }
  47. # append result
  48. results.append(res)
  49. # return results
  50. return results