Current solution
This is super hacky, but best I could come up quickly. Seemed to work with all apps I tried. PHP solution, but you can just pick the preg_match() regex part for any other language.
public function getAndroidVersion(string $storeUrl): string
{
$html = file_get_contents($storeUrl);
$matches = [];
preg_match('/\[\[\[\"\d+\.\d+\.\d+/', $html, $matches);
if (empty($matches) || count($matches) > 1) {
throw new Exception('Could not fetch Android app version info!');
}
return substr(current($matches), 4);
}
Solution until May 2022 (NO LONGER WORKS)
Using PHP backend. This has been working for a year now. It seems Google does not change their DOM that often.
public function getAndroidVersion(string $storeUrl): string
{
$dom = new DOMDocument();
$dom->loadHTML(file_get_contents($storeUrl));
libxml_use_internal_errors(false);
$elements = $dom->getElementsByTagName('span');
$depth = 0;
foreach ($elements as $element) {
foreach ($element->attributes as $attr) {
if ($attr->nodeName === 'class' && $attr->nodeValue === 'htlgb') {
$depth++;
if ($depth === 7) {
return preg_replace('/[^0-9.]/', '', $element->nodeValue);
break 2;
}
}
}
}
}
Even older version (NO LONGER WORKS)
Here is jQuery version to get the version number if anyone else needs it.
$.get("https://play.google.com/store/apps/details?id=" + packageName + "&hl=en", function(data){
console.log($('<div/>').html(data).contents().find('div[itemprop="softwareVersion"]').text().trim());
});