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
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>";
  
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.