michael.davis Posted March 29, 2011 Share Posted March 29, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232085-php-script-extract-temperatures-from-another-website/ Share on other sites More sharing options...
ignace Posted March 29, 2011 Share Posted March 29, 2011 $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. Quote Link to comment https://forums.phpfreaks.com/topic/232085-php-script-extract-temperatures-from-another-website/#findComment-1193806 Share on other sites More sharing options...
michael.davis Posted March 29, 2011 Author Share Posted March 29, 2011 Thanks for the help. This works well. I was checking other sites...and the format is different for each lake. Grrr... How about this link: http://www.fishingnotes.com/lakeinfo.php?id=27931 Thanks! Mike Quote Link to comment https://forums.phpfreaks.com/topic/232085-php-script-extract-temperatures-from-another-website/#findComment-1193811 Share on other sites More sharing options...
ignace Posted March 29, 2011 Share Posted March 29, 2011 I'm not going to write all the code for you. The example I showed was to point you in the right direction. I'm glad to help if you are stuck, though. Look up web scraping, and get comfortable writing RegEx. Quote Link to comment https://forums.phpfreaks.com/topic/232085-php-script-extract-temperatures-from-another-website/#findComment-1193816 Share on other sites More sharing options...
michael.davis Posted March 29, 2011 Author Share Posted March 29, 2011 Well thank you! I appreciate your kind help. I was not intending you to write the code. I am a newby with php and I needed some help, thus I am grateful for. Have a great day! Mike Quote Link to comment https://forums.phpfreaks.com/topic/232085-php-script-extract-temperatures-from-another-website/#findComment-1193820 Share on other sites More sharing options...
ignace Posted March 29, 2011 Share Posted March 29, 2011 Changing The water temperature is ([\d]{1,2}.[\d]{1,2}) degrees to <span id="atemp">([\d]{2}) for example would get you the degrees of the second link. These should be good examples to get you started. Quote Link to comment https://forums.phpfreaks.com/topic/232085-php-script-extract-temperatures-from-another-website/#findComment-1193824 Share on other sites More sharing options...
michael.davis Posted March 31, 2011 Author Share Posted March 31, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/232085-php-script-extract-temperatures-from-another-website/#findComment-1195068 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.