Web Scraping Amazon with PHP

Develop software to help the small bookshop owner to catalog & sell online.

New Project started 2021
User avatar
Stevyn
SysOp
Posts:1776
Joined:Mon Nov 09, 2009 10:03 am
Location:Japan
Contact:
Web Scraping Amazon with PHP

Post by Stevyn » Fri Aug 20, 2021 9:27 am

Web Scraping Amazon with PHP

Code: Select all

/* Enter the Amazon Product ISIN */
    $amazonISIN = "B00OTWNSMM";

    /* Grab the content of the HTML web page */
    $html = file_get_contents("http://www.amazon.com/gp/aw/d/$amazonISIN");

    /* Clean-up */
    $html = str_replace(" ", "", $html);

    /* The magical regex for extracting the price */
    $regex = '/\(Prezzo|Precio|Price|Prix Amazon|Preis):?\<\/b\>([^\<]+)/i';

    /* Return the price */

    if (preg_match($regex, $html, $price)) {
        $price = number_format((float)($price[2]/100), 2, '.', '');
        echo "The price for amazon.com/dp/$amazonISIN is $price";
    } else {
        echo "Sorry, the item is out-of-stock on Amazon";
    }
?>
source: https://www.labnol.org/code/19064-web-scraping-amazon
Contact me directly: Ironfeatherbooks (@) gmail.com

Image

Post Reply