Coolapk 最近突然被喝茶,宣布即将下架所有“非认证开发者发布的应用”,就是说无人认领的国外大厂应用、无人认领的国内个人作品、开发者没有实名认证的国内应用…… 都要被下架。所以像 xposed 那样的重灾区,有备无患嘛!虽然本人并不用 Xposed,但是先抓下来再说 注:使用的是 Python3,外加 Requests

主程序为 Sol.py,外加三个模块 Eros.py, Ganymede.py, Luna.py,均在同一目录下。Sol.py 会按顺序下载包含关键词的所有应用,Eros.py 用来解析搜索列表,Ganymede.py 提取应用列表,Luna.py 解析应用的详细信息。运行主程序,会在程序目录下新建 Pack 目录,每个应用又会在 Pack 中建立自己的目录,其中包括 apk 文件、应用的图标文件、应用的酷安网页文件。注:使用的是 Python3,外加 Requests。

主程序 Sol.py 如下

#!/usr/bin/env python3
import os
import requests
from Eros import Eros
from Ganymede import Ganymede
from Luna import Luna

Protomolecule = ["http://coolapk.com"]
Protomolecule.append(Protomolecule[-1]+"/apk")
Protomolecule.append(Protomolecule[-1]+"/xposed")

DonkeyBalls = ["Mozilla/5.0 (X11; Linux x86_64) "\
        "AppleWebKit/537.36 (KHTML, like Gecko) "\
        "Chrome/58.0.3029.110 Safari/537.36"]

class MCRN(Eros, Ganymede):
    def __init__(self):
        self.BobbieDraper = []
        ChrisjenAvasarala = []
        Belter = 2

        self.Anubis = {"user-agent": DonkeyBalls[0]}
        Razorback = requests.get(Protomolecule[2], headers = self.Anubis)
        DonkeyBalls.append(Razorback.cookies["SESSID"])
        self.Donnager = {"SESSID": DonkeyBalls[-1]}
        ChrisjenAvasarala.append(Razorback)
            # Package group search 1st page

        with Eros() as SadavirErrinwright:
            SadavirErrinwright.feed(ChrisjenAvasarala[0].text)
                # self.SadavirErrwright.Inner now has the max page number

        while Belter <= SadavirErrinwright.Inner:
            Razorback = requests.get(\
                Protomolecule[2]+"/?p="+str(Belter), \
                headers = self.Anubis, \
                cookies = self.Donnager)
            ChrisjenAvasarala.append(Razorback)
            Belter += 1

        for Cotyar in ChrisjenAvasarala:
            with Ganymede() as PyotrKorshunov:
                PyotrKorshunov.feed(Cotyar.text)
            self.BobbieDraper.extend(PyotrKorshunov.Martian)
            del PyotrKorshunov


class Rocinante(MCRN, Luna):
    def __init__(self):
        MCRN.__init__(self)
        Sol = os.path.abspath(__file__)
        Mars = os.path.dirname(Sol)
        os.chdir(Mars)
        os.mkdir("Packs")
        os.chdir("Packs")
        Earth = os.getcwd()

        self.AlexKamal = []     # APK path
        self.AmosBurton = []    # package page html
        self.NaomiNagata = []   # Package
        self.JamesHolden = []

        for KenzoGabriel in self.BobbieDraper:
            PraxidekeMeng = requests.get(\
                Protomolecule[0] + KenzoGabriel, \
                headers = self.Anubis, \
                cookies = self.Donnager)
            print("读取应用网页...")
            print(PraxidekeMeng.url)

            self.AmosBurton.append(PraxidekeMeng.text)
            SolomonEpstein = Luna(PraxidekeMeng.text)

            SolomonEpstein.EpsteinDrive3 = "".join( \
                Solomon for Solomon in SolomonEpstein.EpsteinDrive3
                if Solomon not in "\/`!?@#$%^&*<>|=")

            fuel = 1
            while os.path.exists(SolomonEpstein.EpsteinDrive3):
                fuel += 1
                if fuel > 2:
                    SolomonEpstein.EpsteinDrive3 = \
                        SolomonEpstein.EpsteinDrive3[:-3] +\
                        "("+str(fuel)+")"
                else:
                    SolomonEpstein.EpsteinDrive3 += "(2)"

            os.mkdir(SolomonEpstein.EpsteinDrive3)
            os.chdir(SolomonEpstein.EpsteinDrive3)

            with open(SolomonEpstein.EpsteinDrive4, 'wb') as EpsteinDrive:
                EpsteinDrive.write(requests.get(SolomonEpstein.EpsteinDrive,\
                    headers = self.Anubis,\
                    cookies = self.Donnager).content)

            with open(SolomonEpstein.EpsteinDrive5, 'wb') as EpsteinDrive2:
                EpsteinDrive2.write(requests.get(SolomonEpstein.EpsteinDrive2,\
                    headers = self.Anubis,\
                    cookies = self.Donnager).content)

            with open(SolomonEpstein.EpsteinDrive3+".html", 'wb') as EpsteinDrive3:
                EpsteinDrive3.write(PraxidekeMeng.content)

            del EpsteinDrive, EpsteinDrive2, EpsteinDrive3

            os.chdir(Earth)
            self.AlexKamal.append(SolomonEpstein.EpsteinDrive)
            self.AmosBurton.append(PraxidekeMeng)
            self.NaomiNagata.append(SolomonEpstein.EpsteinDrive4)
            self.JamesHolden.append(SolomonEpstein.EpsteinDrive3)


if __name__ == "__main__":    
    TheExpanse = Rocinante()

Eros.py 如下:

#!/usr/bin/env python3
from html.parser import HTMLParser
from urllib.parse import urlparse, parse_qs

class Eros(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        self.Belta = False
        self.Pampa = []

    def __enter__(self):
        print("获取搜索页...")
        return self

    def handle_starttag(self, tag, attr):
        if (tag == 'div' and attr == [('class','panel-footer '
        'ex-card-footer text-center')]):
            self.Belta = True
        if self.Belta and tag == 'a':
            self.Pampa.append(attr)

    def handle_endtag(self, tag):
        if tag == 'div':
            self.Belta = False

    def handle_data(self, data):
        if data == '最末页':
            self.Inner = self.Pampa[-1][0][1]
            self.Inner = urlparse(self.Inner)
            self.Inner = parse_qs(self.Inner.query)['p'][0]
            self.Inner = int(self.Inner)

    def __exit__(self, exec_type, exec_value, traceback):
        print("获取所有搜索页面...")
        del self.Belta, self.Pampa

Ganymede.py

#!/usr/bin/env python3
from html.parser import HTMLParser

class Ganymede(HTMLParser):
    def __init__(self):
        HTMLParser.__init__(self)
        self.Earther = False
        self.Belter = []
        self.Martian = []

    def __enter__(self):
        print("读取搜索列表...")
        return self

    def handle_starttag(self, tag, attr):
        if tag == "ul" and \
            attr == [("class", "media-list ex-card-app-list")]:
            self.Earther = True
        if self.Earther and tag == "li":
            self.Belter.append(attr)

    def handle_endtag(self, tag):
        if tag == "ul":
            self.Earther = False

    def __exit__(self, exec_type, exec_value, traceback):
        print("获取应用网址...")
        for Belta in self.Belter:
            Belta = dict(Belta)['data-touch-url']
            self.Martian.append(Belta)

        del self.Belter, self.Earther

Luna.py

#!/usr/bin/env python3
from re import search

class Luna():
    def __init__(self, feed):
        self.EpsteinDrive = search(r".*var apkDownloadUrl = \"(\S*?)\"",\
            feed).group(1)
        print("\n解析 apk 文件地址...")
        print(self.EpsteinDrive)

        self.EpsteinDrive2 = search(r".*img\s*class=\"media-object\s*img-rounded\"\s*src=\"(.*?)\"\s*alt=\"(.*?)\"", feed).group(1)
        print("解析应用图片地址...")
        print(self.EpsteinDrive2)

        self.EpsteinDrive3 = search(r".*img\s*class=\"media-object\s*img-rounded\"\s*src=\"(.*?)\"\s*alt=\"(.*?)\"", feed).group(2)
        print("解析应用名称")

        self.EpsteinDrive4 = search(r"\?pn=(\S*?)&", self.EpsteinDrive).group(1)
        print("解析应用包名...")
        print(self.EpsteinDrive4)

        self.EpsteinDrive5 = search(r'.*/(\S*)', self.EpsteinDrive2).group(1)
        print("图片文件名...")
        print(self.EpsteinDrive5)