file_get_contents不会返回PHP中的所有图像
我试图从一个基于URL的网页上获取所有图像。使用Google Chrome查看网页时,我可以看到图像,但使用file_get_contents方法时,我看不到图像file_get_contents不会返回PHP中的所有图像,php,dom,domdocument,Php,Dom,Domdocument,我试图从一个基于URL的网页上获取所有图像。使用Google Chrome查看网页时,我可以看到图像,但使用file_get_contents方法时,我看不到图像 public function getPictureFromUrl($url){ $html = file_get_contents($url); $sContent = htmlspecialchars($html); $dom = new DOMDocument(); @$dom->loadH
public function getPictureFromUrl($url){
$html = file_get_contents($url);
$sContent = htmlspecialchars($html);
$dom = new DOMDocument();
@$dom->loadHTML($sContent);
$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
foreach ($images as $image) {
$src = $image->getAttribute('src');
return $src;
}
return "";
}
$images长度为0。
以下两个链接是我尝试的URL示例:
如何获取图像源?因为Amazon没有为这些图像使用
img
标记,所以可能会使用Javascript将图像添加到DOM中。@HSaiKiran,据我所见,它使用img。你能解释一下吗?@Barmar,请强调一下。我想网站实际上是在检查用户代理。我尝试使用curl
访问它,结果得到了一个错误页面,与使用浏览器得到的页面不同。