apkmirror.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 lxml import html
  10. from searx.engines.xpath import extract_text
  11. from searx.url_utils import urlencode
  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 dom.xpath('.//div[@id="content"]/div[@class="listWidget"]/div[@class="appRow"]'):
  32. link = result.xpath('.//h5/a')[0]
  33. url = base_url + link.attrib.get('href') + '#downloads'
  34. title = extract_text(link)
  35. thumbnail_src = base_url + result.xpath('.//img')[0].attrib.get('src').replace('&w=32&h=32', '&w=64&h=64')
  36. res = {
  37. 'url': url,
  38. 'title': title,
  39. 'thumbnail_src': thumbnail_src
  40. }
  41. # append result
  42. results.append(res)
  43. # return results
  44. return results