外部网址获取图像 [英] External Url get Image

查看:79
本文介绍了外部网址获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用简单的html dom来解析一个外部url并从中获取图像。我可以从80%的外部网址获取图像,但其中一些提供了问题。

I am using simple html dom for parsing an external url and getting images from it. I can get images from 80% externals urls but some of them gives problems. Example Below.

$url = 'http://www.sears.com/shc/s/CountryChooserView?storeId=10153&catalogId=12605';
$html = file_get_html($url);
foreach($html->find('img') as $element) 
{
   $image_url = $element->src;
   echo $image_url;
   echo "<br />";
}   

我可以在本地(23图像),但在服务器上3个图像)它不是。代码就像我上面提到的那样。任何人都可以帮助服务器的行为如何。

I can get this running at local (23 images) but on server(only 3 images) it is not. code is as i mentioned on top. can anybody help why server is behaving so.

谢谢

推荐答案

使用以下脚本

$url="http://example.com";

$html = file_get_contents($url);

$doc = new DOMDocument();
@$doc->loadHTML($html);

$tags = $doc->getElementsByTagName('img');

foreach ($tags as $tag) {
       echo $tag->getAttribute('src');
}

这篇关于外部网址获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆