Skip to content Skip to sidebar Skip to footer

Scraping Javascript Array

I had a problem with scraping a site http://www.weather.bm/radarMobile.asp, Fatherstorm gave me a great solution but it had some minor bugs in regards to start time and number of i

Solution 1:

Read the PHP manual on regular expressions. In this case it's as simple as:

$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

The explode() is easier here than preg_split. But then requires a trim() on each filename in the array, and a second trim($filename, "'") to get rid of the enclosing quotes.

Solution 2:

Try this:

//not testedvarlen=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;

Post a Comment for "Scraping Javascript Array"