刮掉非绝对URL [英] Scraping non-absolute URL

查看:87
本文介绍了刮掉非绝对URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图抓取 www.weather.bm 。我想要所有10个雷达图像,但我只能得到一个(图像定期更新),它不是一个绝对的图像网址。我希望我可以使用图像作为图像幻灯片,如链接,但不知道如何。另外,如何删除 images / Radarlegend.png

包括( 'simple_html_dom.php'); 
$ html = file_get_html('http://www.weather.bm/radarMobile.asp');
foreach($ html-> find('img')as $ element)
echo $ element-> src。 '< br>'

我的输出是:

 < div id =main> 
images / Radar / CurrentRadarAnimation_100km_sri / 100km_sri-radar-2011-01-04-1556.jpg< br> images / Radarlegend.png< br>< / div>
< / div>


解决方案

  $ localOffset =+2小时; //将其更改为您需要的图像时间的本地偏移量。对我来说(CST)是2小时..... 
$ start = strtotime( - 90 Minutes。$ localOffset); //返回90分钟(可用图像的限制)
$ start =($ start - ($ start%(600))+(60 * 6)); ($ x = 1; $ x <= 9; //转到下一个较早的6分钟标记(所有图像看起来在6分钟标记处))似乎在6分钟标记处)。 $ x ++){
$ DateTime = date(Ymd-Hi,$ start); //设置我们想要的图像时间。
$ fName =(http://www.weather.bm/images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-$DateTime.jpg); //设置文件名
echo$ min< img src ='$ fName'alt ='$ fName'/>< br />; // echo(或添加到堆栈或变量...)您的图像节点
$ start + =(600); //添加10分钟
}


I am trying to scrape www.weather.bm. I want all 10 radar images, but I can only get one (the image updates regularly) and it's not a absolute image url. I was hoping I could use the image as a image slideshow like the link but dont know how. Also, how can I remove images/Radarlegend.png? I just need the radar images.

Here is my code:

include('simple_html_dom.php');
$html = file_get_html('http://www.weather.bm/radarMobile.asp');
foreach($html->find('img') as $element) 
echo $element->src . '<br>'

My output is:

<div id="main">
images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1556.jpg<br>images/Radarlegend.png<br></div>
</div>

解决方案

    $localOffset = "+2 Hours"; //change this to your local offset from the image times you need. for me (CST) it's 2 hours.....
    $start=  strtotime("-90 Minutes " . $localOffset); // go back 90 minutes (The limit of the available images)
    $start=($start-($start % (600))+(60*6)); //go to the next earlier 6 minute mark (all images appear to be at the 6 minute mark))appear to be at the 6 minute mark))
    for($x=1;$x<=9;$x++){
        $DateTime = date("Y-m-d-Hi", $start); // set the image time we want.
        $fName = ("http://www.weather.bm/images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-$DateTime.jpg"); // set the filename
        echo" $min <img src='$fName' alt='$fName'/><br/>"; // echo (or add to a stack or variable...) your image node
         $start+=(600);//add 10 minutes
    }

这篇关于刮掉非绝对URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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