如何从Google Play动态获取应用程序图标

Mah*_*ban 5 android google-play

我正在开发一个显示应用程序列表的应用程序,我想从Google Play商店中获取该应用程序的图标,以在列表中显示它,因此,请告诉我。

roa*_*ter 3

我最近在更新我的投资组合网站时不得不自己解决这个问题,所以我什至为您提供了一些代码:)我所做的是在 php 中,但我不确定您想使用什么。首先,我使用视图->开发人员->开发人员工具(在 Chrome 上)检查了页面的源代码以及我的应用程序。然后使用它我可以遍历 DOM 寻找可以用来识别应用程序图标的东西。我找到了这个: 截屏

这表明应用程序图标被保存在类“doc-banner-icon”的div中 - 我在其他地方找不到这个类,所以我理所当然地认为它是该类的唯一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

?>
Run Code Online (Sandbox Code Playgroud)

导致类似
{'imgUrl',' https://lh6.ggpht.com/1WMU4E3lnbjz5yxLHxsPrJAJPw3uYZ8LXk3QkD1EKOxwOcHu0W9QyGlpM5AfrKYEVzzi=w124 '}

关于这种方法只需记住一件事:Google 可以随时更改所有内容的呈现和布局方式,因此请准备好在发生这种情况时更新您的应用程序:)