简体   繁体   中英

Is it possible to download apk from google play programmatically to PC?

I'd like to download a lot of apks from google play to PC and install apk on phone for test.

I have seen that http://apk-dl.com/ can download an apk to pc, so is it possible to do the same thing by using java or python or have some code examples?

Use Google Play Unofficial Python API (github)

Using this API you can download APKs using their package name:

python download.py com.google.android.gm

For finding relevant APKs you can use the search or even parse subcategories

python search.py earth
python list.py WEATHER apps_topselling_free

You could also scrap http://apk-dl.com to get the apk download link, the steps include to first go to http://apk-dl.com/{packageName} and extract the link value in 2 consecutive pages.

A bash example that uses curl to download and pup to parse HTML would be :

#!/bin/bash

package=com.facebook.katana

# Download APK 
temp_link=$(curl -s "http://apk-dl.com/$package" | pup ".download-btn .mdl-button attr{href}")
temp2_link=$(curl -s "http://apk-dl.com/$temp_link" | pup ".detail a attr{href}")
dl_link=$(curl -s "$temp2_link" | pup ".contents a attr{href}")

rm -f app.apk
curl -s -o app.apk "http:$dl_link"

In Java, the following method return the apk download url :

public static String getApkDownloadUrl(final String packageName) throws IOException {

    Elements data = Jsoup.connect("http://apk-dl.com/" + packageName).get().select(".download-btn .mdl-button");

    if (data.size() > 0) {

        Elements data2 = Jsoup.connect("http://apk-dl.com" + data.attr("href")).get()
                .select(".detail a");

        if (data2.size() > 0) {

            Elements data3 = Jsoup.connect(data2.attr("href")).get()
                    .select(".contents a");

            return (data3.size() > 0) ? "http:" + data3.attr("href") : "";
        }
    }
    return "";
}

In Python :

import urllib2
from bs4 import BeautifulSoup
import re

def get_apk_url(package_name): 
    opener = urllib2.build_opener()

    response = opener.open('http://apk-dl.com/' + package_name)
    soup = BeautifulSoup(response.read(), 'html.parser')
    temp_link = soup.find("div",{'class': 'download-btn'}).find("a")["href"]

    response = opener.open('http://apk-dl.com/' + temp_link)
    soup = BeautifulSoup(response.read(), 'html.parser')
    temp_link2 = soup.find("section",{'class': 'detail'}).find("a")["href"]

    response = opener.open(temp_link2)
    soup = BeautifulSoup(response.read(), 'html.parser')
    temp_link3 = soup.find("div",{'class': 'contents'}).find("a")["href"]

    return "http:" + temp_link3

print(get_apk_url('com.facebook.katana'))

在Java中试用: Google Play Downloader

If you're a more casual APK downloader then a Chrome extension is probably not really necessary. Instead, you can just visit a dedicated site for generating APK download links whenever you need to.

Go to the Play Store and find the app you want to download. Copy the app's URL address from the browser's address bar. Next, go to a site like Apk16 APK Downloader (Apk16 also has a Chrome/Firefox extension) and paste the app package name (or the whole Google Play URL if you're lazy) in the box at the top of the page.

Projects wrapping API interaction are either obsolete or fail when Google requires to verify actions in browser. I found it convenient to write a script in UiAutomator.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM