Jump to content

Quick way to get this data?


cooldude832

Recommended Posts

I have the page

http://www.almanac.com/weatherhistory/oneday.php?number=725090&wban=14739&day=1&month=1&year=1946&searchtype=zip

 

and I want to get the mean temperature as I change the year/month anyone know a fast way to retrive just that section

 

what I got so far is

<?php
$year = 1946;
while($year < 2009){
$month = 1;
while($month < 13){
	$page = "http://www.almanac.com/weatherhistory/oneday.php?number=725090&wban=14739&day=1&month=";
	$page .= $month;
	$page .= "&year=";
	$page .= $year;
	$page .= "&searchtype=zipx";
	$data = file_get_contents($page);
                $month++;
       }
       $year++;
}

?>

 

Link to comment
https://forums.phpfreaks.com/topic/91430-quick-way-to-get-this-data/
Share on other sites

if u looked at the html coding for the page

<p style="margin: 3px 0pt; font-size: smaller;">MEAN<br>TEMPERATURE</p>

<b style="font-size: x-large;">30.9</b><b style="font-size: large; font-weight: normal;"><sup>°F</sup></b><br>

<p style="margin: 0pt; font-family: arial,sans-serif; font-size: x-small;">Mean temperature<br>for the day.</p>

 

is what your after

 

with either strpos or preg_match

ya can get the temp

 

I prefer preg_match

<?php
  $contents=file_get_contents('http://www.almanac.com/weatherhistory/oneday.php?number=725090&wban=14739&day=1&month=1&year=1946&searchtype=zip');
  preg_match('@MEAN<br>TEMPERATURE.*?;">([\d\.]+)</b>@ms',$contents,$match);
  $mean=$match[1];
  echo "Mean Temp: $mean<br>";
  
?>

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.