Goquery is used for parsing the HTML output of a website and taking the parts you want to use for something.It is based on Go's net/html package and the CSS Selector library cascadia. I am using it for scraping data. It is really useful. In order to use. First, install goquery:

go get github.com/PuerkitoBio/goquery

I made the request with website :

resp, err := http.Get("http://yourwebsite.com/")
if err != nil {
    fmt.Println(err)
}
defer resp.Body.Close()
// Load the HTML document
doc, err := goquery.NewDocumentFromReader(resp.Body)
if err != nil {
    fmt.Println(err)
}

This is the information i want : My helpful screenshot I am using Chrome Debugger to figure out the structure of above information. My helpful screenshot Next, we will loop for each information:

doc.Find(".centerBoxWrapperContents td").Each(func(i int, item *goquery.Selection) {
    img, isExist := item.Find(".listingProductImage").Attr("src")
    if isExist {
        fmt.Println("image :", img)
        //image : images/nails/acrylic full set.png
    }
    title := item.Find(".itemTitle").Text()
    fmt.Println("Title is : ", title) 
    //Title is :  Acrylics Full Set
    desc := item.Find(".listingDescription").Text()
    price := item.Find(".productBasePrice").Text()
    fmt.Println("description : ", desc)
    //description :  Say goodbye to brittle,...
    fmt.Println("price : ", price)
    //price :  $25.00
})

Sometimes, they do not have specified things to extract (like class or id), like this:

<div>first div</div>
<div>second div</div>
<div>last div</div>

With goquery:

doc.Find("div").First().Text() //first div
doc.Find("div").First().Siblings().Text() //second div
doc.Find("div").Last().Text() //last div

And if you want to compare attribute like this:

<div data-text="menu_simpletwocolumn_menu_items_local1_service">
    Hello
</div>

You can use

div:= doc.Find("[data-text=menu_simpletwocolumn_menu_items_local1_service]").Text()