-1

how can i get the price dynamically from another web page and store it in the server (php and SQL) if not in php it doesn't matter!

for example a web page that doesn't have json or xml but i want to get a specific value from it like the price

i tried a few things that are built in php but it didn't work the way i wanted to.

also this didn't work! :

Access-Control-Allow-Origin: *

i need this for my next project , i will really appreciate your help!

Max
  • 3
  • 1
  • You would have to get the html code using something like `file_get_contents()` then parse it to try to find the price. – Pitchinnate Apr 25 '14 at 19:04
  • What exactly did you try? – JonasVautherin Apr 25 '14 at 19:29
  • i tried file_get_contents but now i want to get 500 different prices that have the same class and save them in a database but if the price changes i want to modify the original price in that database – Max Apr 26 '14 at 12:39

1 Answers1

2

http://www.webmasterworld.com/forum88/10926.htm

How do I get the HTML code of a web page in PHP?

http://www.php.net/file_get_contents

You might start there. You will need to grab all of the HTML and then parse it based on the tags they are using.

From the first website (modified a bit):

$url = 'http://www.example.com'; 
$needle = '<b>find me</b>'; // Look for the tags on the other page and replace here
$contents = file_get_contents($url); 
if(strpos($contents, $needle) !== false) { 
    // Do your saving of the price here;
}

If you have more than one price on the page, you will need to form a loop that finds the next occurrence instead of only the first. Hopefully this helps!

Community
  • 1
  • 1
Newyork167
  • 494
  • 5
  • 9
  • thanks , but what if i want to get 500 different prices all from different pages and i want to save them in the database and when the price changes i want to modify the original price in the database what can i do then ? – Max Apr 26 '14 at 12:36
  • If they are all from the same site and you have a list of all of the webpages you need to access, then you can loop through each webpage (using an array or other list of sorts) and call the above code looking for the price tag. For the modification, when you call the database to save the price, just select the record for the item and if it exists - check if it changed or not and update as needed, if it doesn't exist - create a new entry. – Newyork167 Apr 26 '14 at 12:52
  • Good to hear! Remember to mark the answer so the question is completed here. – Newyork167 Apr 27 '14 at 03:13