Skip to content

Instantly share code, notes, and snippets.

Created Jun 10, 2019
What would you like to do?
ForEach (Name) - Go Colly
package main
import (
func main() {
c := colly.NewCollector()
c.OnRequest(func(r *colly.Request) {
fmt.Println("Visiting", r.URL)
c.OnHTML("", func(e *colly.HTMLElement) {
e.ForEach("div.a-section.a-spacing-medium", func(_ int, e *colly.HTMLElement) {
var productName string
productName = e.ChildText("span.a-size-medium.a-color-base.a-text-normal")
if productName == "" {
// If we can't get any name, we return and go directly to the next element
fmt.Printf("Product Name: %s \n", productName)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment