I've passed Response.Body directly not via other structure field and it worked.
But still, this package("github.com/PuerkitoBio/goquery") is not jQuery. Although it's great, but should be treated differently. My suggestion to the author is to add good description on how selectors should be formed. That's intense! Because now to understand what is going on you don't want but dive into the code to find the source of your suffering! Hear me out! But the package is awesome! Great and hard work! My example is below. It was tested in go.test so there is syntax from there, but to my mind the idea is clear. I would appreciate any comments on that.
import (
"fmt"
"strings"
"github.com/PuerkitoBio/goquery"
)
func Example() {
var clientRequest = &http.Client{
Timeout: 3 * time.Second,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}}
response, err := clientRequest.PostForm(serviceURL, reqBody)
doc, err := goquery.NewDocumentFromReader(response.Body)
if err != nil {
t.Fatal(err)
}
var person []string
j := 0
/* this wonderful package is searching into depth so be sure that your every HTML element you search for has the same selector.
For Example if I've been doing it like that doc.Find("#ctl00_cphBody_gvDebtors")
There would be only one iteration into Each and this will be the String containing all the info
into this selector on the overhand example below contains each of td value of the table
And that's wonderful. If I was the creator of the package I would write it down in the documentation more precisely, cause now, no offense, it sucks!..*/
doc.Find("#yourId td").Each(func(i int, s *goquery.Selection) {
// I don't want the first string into my array, so I filter it
if j != 0 {
person = append(person, strings.TrimSpace(s.Text()))
}
j++
})
fmt.Println(len(person))
}
func main(){
Example()
}