Skip to content

Instantly share code, notes, and snippets.

@cstayyab
Last active September 1, 2020 12:22
Show Gist options
  • Save cstayyab/b99db5c8a5c1f492f85dc708d81a4882 to your computer and use it in GitHub Desktop.
Save cstayyab/b99db5c8a5c1f492f85dc708d81a4882 to your computer and use it in GitHub Desktop.
Fetch App Information from APKPure using BeautifulSoup in Python
# Tested for APKPure Version 1.3.7 (this is website version that prints in Web Browser Console everytime a page from APK Pure Loads)
# Working as of September 1, 2020
import requests
import cssutils
from bs4 import BeautifulSoup
def getAppDataFromAPKPure(apkpure_url): # Example: https://apkpure.com/subway-surfers-1/com.kiloo.subwaysurf
headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Max-Age': '3600',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0'
}
req = requests.get(apkpure_url, headers)
soup = BeautifulSoup(req.content, 'html.parser')
desc_element = soup.select("div.description > div.content")
description = desc_element[0].decode_contents() if desc_element is not None and len(desc_element) > 0 else ""
whatsnew_element = soup.select("div#whatsnew > div:nth-child(3)")
whatsnew = whatsnew_element[0].decode_contents() if whatsnew_element is not None and len(whatsnew_element) > 0 else ""
videoThumbTag_element = soup.select("a.details-tube")
videoThumbURL = ""
videoURL = ""
screenshots = []
if videoThumbTag_element is not None and len(videoThumbTag_element) > 0:
style = videoThumbTag_element[0]['style']
sheet = cssutils.css.CSSStyleSheet()
sheet.add("dummy_selector { %s }" % style)
videoThumbURL = list(cssutils.getUrls(sheet))[0]
videoURL = videoThumbTag_element[0]['data-src']
screenshots_elements = soup.select("a.mpopup > img")
screenshots = [scrn["src"] for scrn in screenshots_elements]
return {
"description": description,
"whatsnew": whatsnew,
"videoThumbnail": videoThumbURL,
"videoURL": videoURL,
"screenshots": screenshots
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment