Pull info from gas price websites?

Reply

Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Pull info from gas price websites?

 
0
  #1
Sep 10th, 2007
Anybody know if there's a way to pull gas prices from any of those gas price websites, so I can display them on my own page? I didn't know if there's a way to tap in to their source or if they provide some sort of way to do that. Reason is I'm writing a little app and I would like to have the gas prices of a couple local stations used in some calculations in my app. An example of one of those sites would be www.gasbuddy.com.

Oh, FYI, the reason I posted this in the PHP forum is that I will be using PHP to write the app.
Last edited by nathanpacker; Sep 10th, 2007 at 4:50 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,484
Reputation: Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of Ezzaral has much to be proud of 
Solved Threads: 517
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: Pull info from gas price websites?

 
0
  #2
Sep 10th, 2007
Here are a couple of tutorials:
http://blogoscoped.com/archive/2004_06_23_index.html

http://www.devnewz.com/devnewz-3-200...eInternet.html

It's just a matter of obtaing the HTML from a request and parsing out the data you need.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: Pull info from gas price websites?

 
0
  #3
Sep 10th, 2007
Hm, good info. I'll take a look into it and let you know how it goes. This just might work. Thanks!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 189
Reputation: martin5211 is an unknown quantity at this point 
Solved Threads: 14
martin5211 martin5211 is offline Offline
Junior Poster

Re: Pull info from gas price websites?

 
1
  #4
Sep 10th, 2007
It is possible to use fopen() in PHP5 to send a POST request and obtain the content in a variable, check this tutorial:
http://netevil.org/blog/2006/nov/htt...p-without-curl

According to the amount of data, sometimes is more fast and useful to use only string functions, with a combination of strpos() and substr(); other method is using regular expressions.
http://www.webcheatsheet.com/php/reg...xpressions.php
http://www.snipwiki.com/snips/show/3...her-substrings

With larger files or complex patterns is recommended to use SimpleXML functions (PHP5), like is described in the first tutorial suggested by Ezzaral. Xpath would be a good improvement to locate elements easily.

Some sites have clean XML results and search API easily obtainable by public, with some limitations, like the Kayak API to search flights in tourism sites. Really, I don’t know if there is a such solution for your industry, some sites contain manuals and examples to implement search and get results on their sites.
Last edited by martin5211; Sep 10th, 2007 at 7:42 pm.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: nathanpacker is an unknown quantity at this point 
Solved Threads: 0
nathanpacker's Avatar
nathanpacker nathanpacker is offline Offline
Posting Whiz in Training

Re: Pull info from gas price websites?

 
0
  #5
Sep 10th, 2007
Thanks for that reply. I will be simply pulling one number every time the script is run. A specific gas price. I'll look into your ideas as well.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 20
Reputation: MKIII is an unknown quantity at this point 
Solved Threads: 0
MKIII MKIII is offline Offline
Newbie Poster

Re: Pull info from gas price websites?

 
0
  #6
Sep 17th, 2007
Interested also. Let me know how this works out. Thanks.
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 61
Reputation: Eko is an unknown quantity at this point 
Solved Threads: 1
Eko's Avatar
Eko Eko is offline Offline
Junior Poster in Training

Re: Pull info from gas price websites?

 
0
  #7
Sep 18th, 2007
This code gets the today's gas price
It's easy to get it on this site because the price is placed between a span with the id "GBPS_lblUSToday"
  1. $arr = file("http://www.gasbuddy.com/");
  2.  
  3. $gasprice = "";
  4. foreach ($arr as $key => $line)
  5. {
  6. if (strstr($line, "GBPS_lblUSToday"))
  7. {
  8. $gasprice=$line;
  9. break;
  10. }
  11. }
  12.  
  13. echo strip_tags($gasprice);

If you need any help,don't hesitate to ask me
"Get rich or die tryin"(50-cent)
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 1
Reputation: ha1e is an unknown quantity at this point 
Solved Threads: 0
ha1e ha1e is offline Offline
Newbie Poster

Re: Pull info from gas price websites?

 
0
  #8
Feb 1st, 2008
Eko I like your code, but can anyone tell me how you would do this for pulling from multiple lines with the same span id?

Many Thanks

ha1e
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC