943,852 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 2885
  • PHP RSS
Sep 10th, 2007
0

Pull info from gas price websites?

Expand Post »
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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Sep 10th, 2007
0

Re: Pull info from gas price websites?

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.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Sep 10th, 2007
0

Re: Pull info from gas price websites?

Hm, good info. I'll take a look into it and let you know how it goes. This just might work. Thanks!
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Sep 10th, 2007
1

Re: Pull info from gas price websites?

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.
Reputation Points: 52
Solved Threads: 23
Posting Whiz in Training
martin5211 is offline Offline
271 posts
since Aug 2007
Sep 10th, 2007
0

Re: Pull info from gas price websites?

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.
Reputation Points: 10
Solved Threads: 0
Posting Whiz in Training
nathanpacker is offline Offline
234 posts
since May 2005
Sep 17th, 2007
0

Re: Pull info from gas price websites?

Interested also. Let me know how this works out. Thanks.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
MKIII is offline Offline
20 posts
since Mar 2007
Sep 18th, 2007
0

Re: Pull info from gas price websites?

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"
PHP Syntax (Toggle Plain Text)
  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
Eko
Reputation Points: 12
Solved Threads: 1
Junior Poster in Training
Eko is offline Offline
60 posts
since Nov 2006
Feb 1st, 2008
0

Re: Pull info from gas price websites?

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ha1e is offline Offline
1 posts
since Feb 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Warning: mysql_connect()
Next Thread in PHP Forum Timeline: php script cron jobs





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC