Skip to content

Instantly share code, notes, and snippets.

@Oshanmateesha2
Forked from dawand/download_apk.py
Created March 11, 2023 05:06
Show Gist options
  • Select an option

  • Save Oshanmateesha2/164a8d3aa8af8bf8d216e6639d2c18f4 to your computer and use it in GitHub Desktop.

Select an option

Save Oshanmateesha2/164a8d3aa8af8bf8d216e6639d2c18f4 to your computer and use it in GitHub Desktop.

Revisions

  1. @dawand dawand revised this gist May 27, 2019. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions download_apk.py
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,10 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    """Download APK files from Google Play Store with Python
    """
    File name: download_apk.py
    Author: Dawand Sulaiman
    Download APK files from Google Play Store with Python
    This script scraps https://apkpure.com to get the apk download link
    Make sure you have BeautifulSoup and urllib libraries
    """
  2. @dawand dawand revised this gist May 27, 2019. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions download_apk.py
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,8 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    """Download APK files from Google Play Store using Python
    Note that all the APKs are grabbed from https://apkpure.com
    """Download APK files from Google Play Store with Python
    This script scraps https://apkpure.com to get the apk download link
    Make sure you have BeautifulSoup and urllib libraries
    """

  3. @dawand dawand created this gist May 27, 2019.
    51 changes: 51 additions & 0 deletions download_apk.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-

    """Download APK files from Google Play Store using Python
    Note that all the APKs are grabbed from https://apkpure.com
    Make sure you have BeautifulSoup and urllib libraries
    """

    from bs4 import BeautifulSoup
    from urllib.parse import quote_plus
    import requests

    def search(query):
    res = requests.get('https://apkpure.com/search?q={}&region='.format(quote_plus(query)), headers={
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.5 (KHTML, like Gecko) '
    'Version/9.1.2 Safari/601.7.5 '
    }).text
    soup = BeautifulSoup(res, "html.parser")
    search_result = soup.find('div', {'id': 'search-res'}).find('dl', {'class': 'search-dl'})
    app_tag = search_result.find('p', {'class': 'search-title'}).find('a')
    download_link = 'https://apkpure.com' + app_tag['href']
    return download_link

    def download(link):
    res = requests.get(link + '/download?from=details', headers={
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.5 (KHTML, like Gecko) '
    'Version/9.1.2 Safari/601.7.5 '
    }).text
    soup = BeautifulSoup(res, "html.parser").find('a', {'id': 'download_link'})
    if soup['href']:
    r = requests.get(soup['href'], stream=True, headers={
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.5 (KHTML, like Gecko) '
    'Version/9.1.2 Safari/601.7.5 '
    })
    with open(link.split('/')[-1] + '.apk', 'wb') as file:
    for chunk in r.iter_content(chunk_size=1024):
    if chunk:
    file.write(chunk)

    def download_apk(app_id):
    download_link = search(app_id)

    if download_link is not None:
    print('Downloading {}.apk ...'.format(download_link))
    download(download_link)
    print('Download completed!')
    else:
    print('No results')

    # Test it
    download_apk('org.moire.opensudoku')