7

我正在开发一个显示应用程序列表的应用程序,我想从 Google Play 商店获取此应用程序的图标以将其显示在列表中,所以如果有任何方法可以做到这一点,请告诉我。

4

3 回答 3

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

?>

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

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

于 2013-02-17T09:34:09.690 回答
1

谷歌不断改变页面结构的问题,到目前为止,我找不到任何资源来以类似于 Apple Store 的官方方式处理这个问题。

无论如何,下面是我今天(2019 年 6 月)使用的 php 代码

PS:在我的代码中,一旦我设法获取图标 URL,我会将其缓存在我的数据库中,因此我不必在 google play store 中再次查找它

          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
        }
于 2019-06-30T05:18:01.773 回答
1

我通过roarster修改了代码以使用 Play 商店的新网页,并对其进行了简化:

<?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

你得到结果;)

于 2016-05-22T08:24:18.167 回答