2016-10-28 74 views
1

我想從iTunes應用程序url中獲取圖標和截圖圖像。但是,我只能抓取特定應用程序的屏幕截圖。 Incase的一個圖標,我得到以下網址https://s.mzstatic.com/htmlResources/ef35/frameworks/images/p.png爲所有apps.I可以獲取圖標和屏幕截圖的谷歌播放的情況下。 所以iTunes是否限制圖標圖像的讀取或者在我的代碼中是否有錯誤?使用SimpleHTMLDOM解析器從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);?> 

回答

1

的問題是使用SRC交換,而不是作爲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; 
} 
相關問題