使用 SimpleHTMLDOM 解析器从 iTunes 获取应用程序的图标图像
Fetching icon image of apps from itunes using SimpleHTMLDOM parser
我正在尝试从 iTunes 应用程序获取图标和屏幕截图图像 url.However 我只能获取特定应用程序的屏幕截图。如果是图标,我得到以下 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.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);?>
问题已通过使用 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;
}
我正在尝试从 iTunes 应用程序获取图标和屏幕截图图像 url.However 我只能获取特定应用程序的屏幕截图。如果是图标,我得到以下 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.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);?>
问题已通过使用 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;
}