Jump to content

PHP Script - Extract temperatures from another website


michael.davis

Recommended Posts

Hi!

 

I am working on a web page running a php script to extract from another website water temperatures from around the area.  I have been working on this for about a month, and dont know how to do this. 

 

Here is where I am trying to grab the data from: http://www.lrn.usace.army.mil/pao/lakeinfo/CEN.htm

---------------------------------------------------------------------------------

This is the data I need to obtain:

 

Fishing is reported to be fair.  Bass are being caught on spinnerbaits, plastic worms and jigs. Some Crappie are being caught on jigs and minnows. Trout are being taken in the tailwater area.

 

The lake elevation is 633.87 feet above mean sea level.  The water temperature is 58.0 degrees on the surface, 50.0 degrees at 10 feet.  Ensure all required safety equipment is onboard your boat and in workable condition.

 

I am wanting to do this for a couple of other lakes with the same data format.

 

Can anyone help?

 

Thanks in advance!

Mike

$html = file_get_contents('http://www.lrn.usace.army.mil/pao/lakeinfo/CEN.htm');
preg_match('~The water temperature is ([\d]{1,2}.[\d]{1,2}) degrees~', $html, $match);
echo $match[1];

 

Something like that should work.

Hi!

 

Again, thank you for you kind help on this!  I did not even know that it was called web scrapping!  :)  Easy enough.

 

Well here is what I have done to make things work on my end:

 

  <?php

//old Hickory

$deg = ('°');

$html = file_get_contents('http://www.fishingnotes.com/lakeinfo.php?id=27931');

preg_match('~Est Water Temperature.*?([\d]{1,2}).&?deg.*?<br><br>~', $html, $match);

echo $match[1];

echo $deg;

 

 

?>

 

Gonna add a few more features to color code temperatures.  Should be fun.

 

Thank you again.  I really do appreciate your help on this.  You have taught me a couple of things.

 

Mike

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.