2011-01-10 61 views
-1

我在抓取一個網站http://www.weather.bm/radarMobile.asp,Fatherstorm gave me a great solution時遇到了問題,但它在開始時間和圖像數量方面有一些小錯誤,有時會給出9或10,但代碼設置爲10。抓取javascript數組

另外一個人(marcog)給我this answer

「,通過含radarFileNames =新的陣列將返回該行的行一個簡單的搜索然後你就可以提取網址有兩個preg_split() s:首先在\(|\)上,然後將第二個標記拆分爲', '。最後,將前綴http://www.weather.bm/添加到URL中。「

我希望如果有人能告訴我他正在談論的代碼。我喜歡學習這種東西,但我沒有人教我。我希望你們能幫助

JavaScript數組:

radarFileNames = new Arra(  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1446.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1456.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1506.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1516.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1526.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1536.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1546.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1556.jpg',  
'images/Radar/CurrentRadarAnimation_100km_sri/100km_sri-radar-2011-01-04-1606.jpg' 

也將有可能輸出UL LI /李/ UL裏面的IMG它有它自己的類(UL類鋰類)

林也用簡單的HTML DOM解析器,但使用fatherstorm代碼 http://j2sdesign.com/rgw/article/20101222/NEWS01/712229951/0/example/r1.php

樣品我不能只加載的圖像是outputed

這裏的圖片10

我從fatherstorm

?php 
     $localOffset = "+2 Hours"; //change this to your local offset from the image times you need. for me it's 1 hours..... 
     $start = strtotime("-100 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)) 
     for ($x = 1; $x <= 10; $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" <center>$DateTime</center> <img class='radarImg' src='$fName' alt='$fName' title='$fName'/><br/."; // echo (or add to a stack or variable...) your image node 
      $start+= (600); //add 10 minutes 


     } 
     ? 

馬里奧代碼你的意思 這樣的:

<?php 
     $localOffset = "+2 Hours"; //change this to your local offset from the image times you need. for me it's 1 hours..... 
     $start = strtotime("-100 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)) 
     for ($x = 1; $x <= 10; $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" <center>$DateTime</center> <img class='radarImg' src='$fName' alt='$fName' title='$fName'/><br/."; // echo (or add to a stack or variable...) your image node 
      $start+= (600); //add 10 minutes 
     $html = file_get_contents('http://www.weather.bm/radarMobile.asp'); preg_match('/radarFileNames = new Array\((.+?)\);/ims', $html, $m); $files = explode(",", $m[1]); 

     } 
     ?> 
+2

我在這裏沒有真正看到問題。你爲什麼不要求marco澄清? –

+0

-1,這是一個gimme teh codez post。 – goat

回答

0

試試這個:

//not tested 
var len=radarFileNames.length, links=''; 

for(var i=0; i<len; i++) { 
    var links = links + '<a href="radarFileNames[i]">'+radarFileNames[i] + '</a>'; 
} 

document.getElementById("some_id").innerHTML = links; 
+0

謝謝你的幫助,但我在哪裏可以把這個代碼,我在哪裏把網站的URL解壓縮,謝謝 – cooldude

1

閱讀PHP手冊上的正則表達式。在這種情況下,它很簡單:

$html = file_get_contents('http://www.weather.bm/radarMobile.asp'); 
preg_match('/radarFileNames = new Array\((.+?)\);/ims', $html, $m); 
$files = explode(",", $m[1]); 
// then output <img>s 

explode()比preg_split更容易。但之後需要在陣列中的每個文件名上有trim(),並且需要第二個trim($filename, "'")來擺脫封閉引號。

+0

我在哪裏可以插入這段代碼我使用 – cooldude

+0

我在哪裏可以添加你的代碼我編輯過我的帖子並添加我的代碼不是你的勺子餵我,但我不知道該怎麼做謝謝你的幫助。或者你的意思是我應該使用simplehtmldon解析器? – cooldude

+0

@cooldude:這是爲了提取。不屬於解決方法代碼。好吧,看看編輯。沒有simplehtmldom解析器必要。 – mario