package main
import (
"fmt"
"github.com/PuerkitoBio/goquery"
"net/http"
)
func main() {
url := "https://books.toscrape.com"
resp, err := http.Get(url)
if err != nil {
fmt.Println(err)
}
defer resp.Body.Close()
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
fmt.Println(err)
}
doc.Find(".product_pod").Each(func(i int, selection *goquery.Selection) {
title := selection.Find(".image_container").Find("img")
price := selection.Find(".price_color").Text()
fmt.Printf("Title: %s, Price: %s\n", title, price)
})
}
I am trying to use goquery to extract the Title from https://books.toscrape.com, I already extracted the prices, but I am having trouble extracting the title since it has multiple attributes.
This is how you print it with the colly library Except, I'm not trying to do it with the colly, I'm trying to do it with goquery. Here is the website: https://books.toscrape.com
title := e.ChildAttr(".image_container img", "alt")
})```