apkmirror.py 1.6 KB

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