I am trying to get a product price using php and file_get_contents function. Here is my code. It is loading the whole page however I just need the price from this page. Can someone please help? Thanks
JavaScript
x
<?php
$homepage = file_get_contents('https://www.snapdeal.com/product/bhawna-collection-loard-shiv-trishul/672311651336');
echo $homepage;
?>
Advertisement
Answer
PHP Simple HTML DOM parser is a godsend for this kind of thing
Get the code here
Just include it on your php
JavaScript
require_once('./path/to/SimpleHtmlDom.php');
// Create DOM from URL or file
$html = file_get_html('https://www.snapdeal.com/product/bhawna-collection-loard-shiv-trishul/672311651336');
// Find all images
$price = $html->find('.pdp-final-price .payBlkBig', 0)->plaintext;
More about this awesome tool