coder coder - 1 month ago 15
PHP Question

Fetching icon image of apps from itunes using SimpleHTMLDOM parser

I am trying to fetch icon and screenshot images from itunes app url.However I can only fetch screenshot of a particular app. Incase of a icon, I get the following url https://s.mzstatic.com/htmlResources/ef35/frameworks/images/p.png for all apps.I can fetch both icon and screenshot in case of google play.So does itunes restrict the fetching of icon images or is there a error in my code?

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

Answer

The problem was solved by using src-swap instead of src as src does not fetch the actual image path.

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

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

}