mattchambers mattchambers - 1 month ago 6
PHP Question

PHP How to scrape content from this specific URL

Can someone please tell me how they would personally get the price of the product from pages like this URL https://www.wayfair.com/The-Childrens-Factory-48-H-x-24-W-Mirror-CF332-132-GBS1086.html

I've been trying for days with no luck.

Your help is appreciated.

Answer

Copy-paste next code in a PHP file and run it in your browser :

<?php
// ▼ FIRST, GET THE WHOLE HTML FROM THE WEB PAGE.
$all = file_get_contents("https://www.wayfair.com/The-Childrens-Factory-48-H-x-24-W-Mirror-CF332-132-GBS1086.html");
$pos = strpos( $all,"dynamic-sku-price" ); // ◄■■ PRICE TAG.
$pos += 36; // SKIP SOME HTML CHARS.
while ( $all[ $pos ] != chr( 10 ) ) // ◄■■ GET PRICE CHARS UNTIL END OF LINE.
{ echo $all[ $pos ];
  $pos++;
}
?>