Skip to content

Commit 7294391

Browse files
authored
Create apkpull.py
1 parent 5258884 commit 7294391

1 file changed

Lines changed: 57 additions & 0 deletions

File tree

apkpull.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
"""
4+
File name: download_apk.py
5+
Author: Dawand Sulaiman
6+
7+
Download APK files from Google Play Store with Python
8+
This script scraps https://apkpure.com to get the apk download link
9+
Make sure you have BeautifulSoup and urllib libraries
10+
"""
11+
12+
from bs4 import BeautifulSoup
13+
from urllib.parse import quote_plus
14+
import requests
15+
16+
17+
def search(query):
18+
res = requests.get('https://apkpure.com/search?q={}&region='.format(quote_plus(query)), headers={
19+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.5 (KHTML, like Gecko) '
20+
'Version/9.1.2 Safari/601.7.5 '
21+
}).text
22+
soup = BeautifulSoup(res, "html.parser")
23+
search_result = soup.find('div', {'id': 'search-res'}).find('dl', {'class': 'search-dl'})
24+
app_tag = search_result.find('p', {'class': 'search-title'}).find('a')
25+
download_link = 'https://apkpure.com' + app_tag['href']
26+
return download_link
27+
28+
def download(link):
29+
res = requests.get(link + '/download?from=details', headers={
30+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.5 (KHTML, like Gecko) '
31+
'Version/9.1.2 Safari/601.7.5 '
32+
}).text
33+
soup = BeautifulSoup(res, "html.parser").find('a', {'id': 'download_link'})
34+
if soup['href']:
35+
r = requests.get(soup['href'], stream=True, headers={
36+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/601.7.5 (KHTML, like Gecko) '
37+
'Version/9.1.2 Safari/601.7.5 '
38+
})
39+
with open(link.split('/')[-1] + '.apk', 'wb') as file:
40+
for chunk in r.iter_content(chunk_size=1024):
41+
if chunk:
42+
file.write(chunk)
43+
44+
def download_apk(app_id):
45+
download_link = search(app_id)
46+
47+
if download_link is not None:
48+
print('Downloading {}.apk ...'.format(download_link))
49+
download(download_link)
50+
print('Download completed!')
51+
else:
52+
print('No results')
53+
54+
# Test it
55+
filename = input("app name?:")
56+
download_apk(filename)
57+
print(search(filename))

0 commit comments

Comments
 (0)