Skip to content
Advertisement

Getting a product price from an ecommerce site using file get content

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

<?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

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

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement