Forum Replies Created

  • For stock availability, use Colly to find the element that indicates whether the product is in stock or out of stock. Extract the text from the element, which might show terms like “In Stock” or “Out of Stock.”

    package main
    import (
    	"fmt"
    	"log"
    	"github.com/gocolly/colly"
    )
    func main() {
    	// Create a new collector
    	c := colly.NewCollector()
    	// Extract stock availability
    	c.OnHTML(".stock-status", func(e *colly.HTMLElement) {
    		fmt.Println("Stock Availability:", e.Text)
    	})
    	// Visit the product page
    	err := c.Visit("https://www.argos.co.uk/product-page")
    	if err != nil {
    		log.Fatal(err)
    	}
    }
    
  • To scrape promotions, locate the section where discounts or special offers are displayed. Use page.$eval() to extract the promotion text. This is often presented as a percentage discount or special note within the product section.

    const puppeteer = require('puppeteer');
    (async () => {
        const browser = await puppeteer.launch({ headless: true });
        const page = await browser.newPage();
        await page.goto('https://www.pontofrio.com.br/product-page');
        // Scrape promotions
        const promotions = await page.$eval('.product-promotion', el => el.innerText.trim());
        console.log('Promotions:', promotions);
        await browser.close();
    })();