Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
file_get_contents不会返回PHP中的所有图像_Php_Dom_Domdocument - Fatal编程技术网

file_get_contents不会返回PHP中的所有图像

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

我试图从一个基于URL的网页上获取所有图像。使用Google Chrome查看网页时,我可以看到图像,但使用file_get_contents方法时,我看不到图像

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示例:

我无法从该代码中获取TV img src


如何获取图像源?

因为Amazon没有为这些图像使用
img
标记,所以可能会使用Javascript将图像添加到DOM中。@HSaiKiran,据我所见,它使用img。你能解释一下吗?@Barmar,请强调一下。我想网站实际上是在检查用户代理。我尝试使用
curl
访问它,结果得到了一个错误页面,与使用浏览器得到的页面不同。