我正在开发一个应用程序,它会显示一系列应用程序,我想从Google Play商店获取这些应用程序的图标以在列表中显示它们。如果有任何方法可以做到这一点,请告诉我。
我正在开发一个应用程序,它会显示一系列应用程序,我想从Google Play商店获取这些应用程序的图标以在列表中显示它们。如果有任何方法可以做到这一点,请告诉我。
最近我在更新我的作品集网站时,不得不自己解决这个问题,所以我有一些代码可以提供给您:)我使用的是php,但我不确定您想要使用什么语言。首先,我使用Chrome浏览器的“查看” -> “开发者” -> “开发者工具”检查了包含应用程序的页面的源代码。然后,我使用DOM遍历查找可以用于标识应用图标的内容。我发现这样一个元素:
这表明应用程序图标被包含在一个类名为“doc-banner-icon”的div中——我在其他地方找不到这个类,所以我认为它是唯一的。然后,在我的php代码中,我使用simpledomparser加载URL、定位图标并输出其URL,如下所示:
<?php
include('simple_html_dom.php');
$html = file_get_html("https://play.google.com/store/apps/details?id=com.smithyproductions.swissarmycarrot"); //put your app id here
$bannerImage = $html->find('.doc-banner-icon'); //the class we found before
$img = $bannerImage[0]->find('img'); //find the img tag inside the div
$imgUrl = $img[0]->src; //get its src url
$arr = array(); //in my own example I filled this array with other things like the title an screenshots
$arr['imgUrl'] = $imgUrl;
echo json_encode($arr); //output it in an easy to read format
?>
这会导致类似以下的结果
{'imgUrl','https://lh6.ggpht.com/1WMU4E3lnbjz5yxLHxsPrJAJPw3uYZ8LXk3QkD1EKOxwOcHu0W9QyGlpM5AfrKYEVzzi=w124'}
需要记住的一点是,谷歌可能随时更改所有内容的呈现和布局,因此请准备好在发生更改时更新您的应用程序 :)
'div.cover-container img.cover-image'
。虽然是个好主意,但完全不可靠。 - camelCaseCoder try{
$lookupData = @file_get_contents('https://play.google.com/store/apps/details?id=com.google.android.gm&hl=en');
// Not valid any more
$pregString = '/<meta itemprop="image" content="(.*?)"\/>/';
//June 2019
$pregString = '/<img src="(.*?)" srcset=".*" class=".*" aria-hidden="true" alt="Cover art" itemprop="image">/';
preg_match($pregString, $lookupData, $output);
} catch (\Throwable $e) {
$error = $e->getMessage();
if (strpos($error, '404 Not Found') === false) {
//unknown error
}else{
//Package not found, use default icon or something
}
}
if(isset($output[1])){
//Store $output[1];
}else{
//icon not found, use default icon or something
}
我修改了roarster的代码,使其能够与Play Store的新网页配合使用,并进行了简化:
<?php
include('simple_html_dom.php');
$play_link = $_GET['playlink']; //Play store link
$html = file_get_html($play_link); //put your app id here
$bannerImage = $html->find('div.cover-container'); //the class we found before
$img = $bannerImage[0]->find('img'); //find the img tag inside the div
$imgUrl = $img[0]->src; //get its src url
$arr = array(); //in my own example I filled this array with other things like the title an screenshots
$arr['imgUrl'] = $imgUrl;
echo json_encode($arr); //output it in an easy to read format
?>
yourwebpage.com/script.php?playlink=https://play.google.com/store/apps/details?id=com.igg.android.im
,然后你会得到结果 ;)