【问题标题】:Fetching icon image of apps from itunes using SimpleHTMLDOM parser使用 SimpleHTMLDOM 解析器从 iTunes 中获取应用程序的图标图像
【发布时间】:2017-03-11 06:28:47
【问题描述】:

我正在尝试从 iTunes 应用程序 url 获取图标和屏幕截图图像。但是我只能获取特定应用程序的屏幕截图。如果是图标,我会为所有应用程序获取以下 URL https://s.mzstatic.com/htmlResources/ef35/frameworks/images/p.png。如果是 google play,我可以同时获取图标和屏幕截图。iTunes 是否限制图标图像的获取或者我的代码中有错误?

 <?php
 // Report all PHP errors (see changelog)
 error_reporting(E_ALL);

include('simplehtmldom_1_5/simple_html_dom.php');

//base url
     $base = "https://itunes.apple.com/cn/app/kindle/id405399194?mt=12&ign-mpt=uo%3D2";

   if (strpos($base, 'play.google.com') !== false) {

     $html_base = file_get_html( $base );
     $icon = "https:".$html_base->find('div[class=details-info] img[class=cover-image]')[0]->src;
     echo  $icon."<br>";
     $screenShot = "https:".$html_base->find('div[class=screenshot-align-inner] img')[0]->src;
     echo $screenShot;

}elseif (strpos($base,'itunes.apple.com') !== false) {

     $html_base = file_get_html( $base );
     $icon = $html_base->find('div[class=artwork] img')[4]->src;
     echo  $icon."<br>";
     $screenShot = $html_base->find('div[class=lockup] img')[0]->src;
     echo $screenShot;

}
 $html_base->clear();
 unset($html_base);?>

【问题讨论】:

    标签: php html-parsing itunes simple-html-dom


    【解决方案1】:

    问题已通过使用 src-swap 而不是 src 解决,因为 src 不获取实际的图像路径。

    }elseif (strpos($base,'itunes.apple.com') !== false) {
    
     $html_base = file_get_html( $base );
     $icon = $html_base->find('div[class=artwork] img')[4]->{'src-swap'};
     //the main icon for itunes is atleast 175px
     echo  $icon."<br>";
     $screenShot = $html_base->find('div[class=lockup] img')[0]->src;
     echo $screenShot;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-18
      • 2011-12-14
      • 2013-04-14
      • 1970-01-01
      • 2012-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多