#Help me understand pointer please

26 messages · Page 1 of 1 (latest)

tender crater
#
func checkerro(err error)error  {
    if err != nil {
        log.Fatal(err)
    }
    return nil
}

func main()  {
    resp, err := http.Get("link")
    checkerro(err)
    doc, err := html.Parse(resp.Body)
    checkerro(err)
    log.Println(doc.Parent)
}````
I did this and i have this output : 2023/03/20 10:06:08 &{<nil> 0x14000248070 0x140002480e0 <nil> <nil> 2    []}

And i want to understand what it means if i face the same issues in other things
lament cloak
#

You should try log.Fatalf("%v", err)

tender crater
#

There is no error is the result i want understand

cloud sparrow
#

the output is a condensed formatting of the internal struct you passed

#
%v    the value in a default format
    when printing structs, the plus flag (%+v) adds field names
tender crater
cloud sparrow
#

what content

tender crater
#

c &{Parent:0x140000e6070 FirstChild:<nil> LastChild:<nil> PrevSibling:<nil> NextSibling:0x140000e6150 Type:5 DataAtom: Data:html Namespace: Attr:[]}

cloud sparrow
#

what do you expect to see

tender crater
#

i get a url and i parsed it to view the content and scrap it

#

the content of the page or url in this case

jaunty valley
tender crater
#

i want this but parsed not in string

#

@cloud sparrow

jaunty valley
#

you need to walk the tree, doc is the parsed html.

jaunty valley
cloud sparrow
#

show some code you tried to print doc.Parent which is a struct of Node
https://pkg.go.dev/golang.org/x/net/html#Node

type Node struct {
    Parent, FirstChild, LastChild, PrevSibling, NextSibling *Node

    Type      NodeType
    DataAtom  atom.Atom
    Data      string
    Namespace string
    Attr      []Attribute
}

you should show us how you got what you got
i assume that's just "data" field which stores everything in plain text

jaunty valley
#

think about linked list. but instead of pointers to prev and next element, you have Parent, FirstChild, LastChild, PrevSibling, NextSibling.

tender crater
jaunty valley
#

why do you want to see it?

tender crater
tender crater
#

And then walk the three to get what i wanna get

jaunty valley