News Feed Forums General Web Scraping Scrape product name, price, stock availability from Argos UK using Go and Colly?

  • Scrape product name, price, stock availability from Argos UK using Go and Colly?

    Posted by Elisabeth Ishita on 12/12/2024 at 11:02 am

    To scrape the product name from Argos UK, you can use Go with the Colly library for web scraping. The product name is typically found in an h1 or span tag. Use Colly’s OnHTML method to target the appropriate element and extract its text.

    package main
    import (
    	"fmt"
    	"log"
    	"github.com/gocolly/colly"
    )
    func main() {
    	// Create a new collector
    	c := colly.NewCollector()
    	// Extract product name
    	c.OnHTML("h1.product-title", func(e *colly.HTMLElement) {
    		fmt.Println("Product Name:", e.Text)
    	})
    	// Visit the product page
    	err := c.Visit("https://www.argos.co.uk/product-page")
    	if err != nil {
    		log.Fatal(err)
    	}
    }
    
    Monica Nerva replied 1 week, 2 days ago 3 Members · 2 Replies
  • 2 Replies
  • Shyamala Laura

    Member
    12/13/2024 at 8:04 am

    To scrape the price, use Colly to locate the price element, usually within a div or span tag. You can use the OnHTML method to fetch the element and extract its text.

    package main
    import (
    	"fmt"
    	"log"
    	"github.com/gocolly/colly"
    )
    func main() {
    	// Create a new collector
    	c := colly.NewCollector()
    	// Extract product price
    	c.OnHTML(".product-price", func(e *colly.HTMLElement) {
    		fmt.Println("Price:", e.Text)
    	})
    	// Visit the product page
    	err := c.Visit("https://www.argos.co.uk/product-page")
    	if err != nil {
    		log.Fatal(err)
    	}
    }
    
  • Monica Nerva

    Member
    12/13/2024 at 11:03 am

    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)
    	}
    }
    

Log in to reply.