Forum Replies Created

  • To scrape product images, identify the img tags containing image URLs, usually part of a gallery. Use Selenium to extract the src attribute for all available images on the page.

    from selenium import webdriver
    from selenium.webdriver.common.by import By
    driver = webdriver.Chrome()
    driver.get('https://www.amazon.com.br/dp/product-page')
    # Scrape product images
    images = driver.find_elements(By.CSS_SELECTOR, '.product-image-gallery img')
    for img in images:
        print('Image URL:', img.get_attribute('src'))
    driver.quit()
    
  • 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)
    	}
    }