News Feed Forums General Web Scraping Scrape product details, ratings, and delivery info ASOS UK using PHP and Guzzle?

  • Scrape product details, ratings, and delivery info ASOS UK using PHP and Guzzle?

    Posted by Lucianus Hallie on 12/12/2024 at 11:14 am

    To scrape product details from ASOS UK, use PHP with the Guzzle HTTP client to fetch the page content and DOMDocument to parse the HTML. Product details such as name and description are typically found in div or span elements.

    <?php
    require 'vendor/autoload.php';
    use GuzzleHttp\Client;
    // Initialize Guzzle client
    $client = new Client();
    $response = $client->get('https://www.asos.com/product-page');
    $html = $response->getBody()->getContents();
    // Load HTML into DOMDocument
    $dom = new DOMDocument;
    libxml_use_internal_errors(true);
    $dom->loadHTML($html);
    libxml_clear_errors();
    // Extract product details
    $xpath = new DOMXPath($dom);
    $productName = $xpath->query('//h1[@class="product-title"]')->item(0)->nodeValue;
    echo "Product Name: $productName\n";
    ?>
    
    Heiko Nanda replied 1 week, 1 day ago 3 Members · 2 Replies
  • 2 Replies
  • Nitin Annemarie

    Member
    12/13/2024 at 10:50 am

    To scrape ratings, locate the element displaying customer ratings, often in a span or div tag. Use DOMXPath to select and extract the rating value.

    <?php
    require 'vendor/autoload.php';
    use GuzzleHttp\Client;
    // Initialize Guzzle client
    $client = new Client();
    $response = $client->get('https://www.asos.com/product-page');
    $html = $response->getBody()->getContents();
    // Load HTML into DOMDocument
    $dom = new DOMDocument;
    libxml_use_internal_errors(true);
    $dom->loadHTML($html);
    libxml_clear_errors();
    // Extract product ratings
    $xpath = new DOMXPath($dom);
    $rating = $xpath->query('//span[@class="product-rating"]')->item(0)->nodeValue;
    echo "Rating: $rating\n";
    ?>
    
  • Heiko Nanda

    Member
    12/14/2024 at 7:33 am

    To scrape delivery information, find the section listing shipping options or delivery times, often located in a div or span tag. Use PHP with DOMXPath to extract this information.

    <?php
    require 'vendor/autoload.php';
    use GuzzleHttp\Client;
    // Initialize Guzzle client
    $client = new Client();
    $response = $client->get('https://www.asos.com/product-page');
    $html = $response->getBody()->getContents();
    // Load HTML into DOMDocument
    $dom = new DOMDocument;
    libxml_use_internal_errors(true);
    $dom->loadHTML($html);
    libxml_clear_errors();
    // Extract delivery information
    $xpath = new DOMXPath($dom);
    $delivery = $xpath->query('//div[@class="delivery-options"]')->item(0)->nodeValue;
    echo "Delivery Information: $delivery\n";
    ?>
    

Log in to reply.