All
I am using PHP Simple HTML DOM Parser to getting product details like Title & Price.
This is the code
<?php
// Include the library
include('simple_html_dom.php');
// Retrieve the DOM from a given URL
$html = file_get_html('http://www.flipkart.com/mobiles/micromax');
// Find all SPAN tags that have a class of "myClass"
foreach($html->find('a.title') as $e){
echo 'Title: '.$e->outertext . '<br>';
//$html = file_get_html('http://www.flipkart.com/mobiles/micromax/'.$e->outertext);
}
foreach($html->find('span.final-price') as $e)
echo 'Price:'.$e->outertext . '<br>';
?>
Result
Title: Micromax X101 (White)
Title: Micromax X291 (White)
Title: Micromax X101 (Yellow)
Title: Micromax X234+ (Wine Red)
Title: Micromax Ninja 3 A57 (Black)
Title: Micromax Ninja 4.0 A87 (Black)
Title: Micromax Bling Q55 (Pearl White)
Title: Micromax X222 (Cocoa Brown)
Title: Micromax X263 (Champagne & Coffee)
Title: Micromax X650 (Silver White)
Title: Micromax A73 (Black)
Title: Micromax X1i XTRA (Black)
Title: Micromax Superfone Lite A75 (Charcoal Black)
Title: Micromax X271 (Black & Blue)
Title: Micromax X50 (Black)
Title: Micromax Q56 (Baby Pink)
Title: Micromax X104 (Black)
Title: Micromax Q22 (Black Green)
Title: Micromax Aisha A52 (Yellow)
Title: Micromax A78 (Coffee)
Price:Rs. 999
Price:Rs. 1910
Price:Rs. 999
Price:Rs. 1190
Price:Rs. 4999
Price:Rs. 6049
Price:Rs. 3130
Price:Rs. 2040
Price:Rs. 1735
Price:Rs. 3350
Price:Rs. 6199
Price:Rs. 1525
Price:Rs. 6299
Price:Rs. 1590
Price:Rs. 4850
Price:Rs. 3999
Price:Rs. 1099
Price:Rs. 1880
Price:Rs. 4699
Price:Rs. 6970
This works fine, but open this page in your browser http://www.flipkart.com/mobiles/micromax. There is ajax product load functionality.
So my script just getting initial loaded products only. I want to get all the products.
You can see “Showing 1-20 of 78”. How to get all 78 products details?
You could read their number of products and divide by 20 as 20 are they display and use their AJAX script to get values. This way you can avoid
simple_html_domand decode json string:and so on.
You just need to check what script it’s called during page scroll. In Google Chrome you can use
Developer Tools, open with F12 and watch for Network section.