How can I parse value in a span in golang from a web page?

I am trying to scrape a list of names of top products from an e-commerce site. However the result of empty. Want to know what is missing. The output is : Visiting: End of scraping:

code :
package main

import (



func main() {
fetchURL := “
fileName := “results.csv”
file, err := os.Create(fileName)
if err != nil {
log.Fatal(“ERROR: Could not create file %q: %s\n”, fileName, err)
defer file.Close()
writer := csv.NewWriter(file)
defer writer.Flush()

writer.Write([]string{"Sl. No."})

c := colly.NewCollector()

c.OnRequest(func(r *colly.Request) {
    fmt.Println("Visiting: ", r.URL)

c.OnHTML(`.a-section a-spacing-none aok-relative`, func(e *colly.HTMLElement) {
    number := e.ChildText(".zg-badge-text")
    name := e.ChildText(".p13n-sc-truncated")



fmt.Println("End of scraping: ", fetchURL)


As you can see, the code in your question is hard to read. This forum provides a feature to indent and format code in a readable way. Just edit your question, select the code and hit the </> button. Done!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.