| | |
Pull info from gas price websites?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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.
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.
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.
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.
•
•
Join Date: Aug 2007
Posts: 189
Reputation:
Solved Threads: 14
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.
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.
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"
If you need any help,don't hesitate to ask me
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)
$arr = file("http://www.gasbuddy.com/"); $gasprice = ""; foreach ($arr as $key => $line) { if (strstr($line, "GBPS_lblUSToday")) { $gasprice=$line; break; } } echo strip_tags($gasprice);
If you need any help,don't hesitate to ask me
"Get rich or die tryin"(50-cent)
![]() |
Similar Threads
- How to use a Hyperlink to send info to a servlet (JSP)
- Insert Dataset into SQL Database. (VB.NET)
- 13 Niches Websites For Sale (Websites for Sale)
- pulling info from foxpro db via asp? help! (ASP.NET)
- Websites For Sale (Websites for Sale)
- Banner ad available on PR 4 site and a Proxy site ! (Ad Space for Sale)
- Parse error: parse error, unexpected T_STRING (PHP)
- Clearing b-4 selling... (Storage)
- homepage hijack "Search for..." about:blank in address (Viruses, Spyware and other Nasties)
- pc won't see hard drive (Storage)
Other Threads in the PHP Forum
- Previous Thread: Warning: mysql_connect()
- Next Thread: php script cron jobs
| Thread Tools | Search this Thread |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube






