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
#Help me understand pointer please
26 messages · Page 1 of 1 (latest)
You should try log.Fatalf("%v", err)
There is no error is the result i want understand
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
ok but how can i view the content ?
what content
c &{Parent:0x140000e6070 FirstChild:<nil> LastChild:<nil> PrevSibling:<nil> NextSibling:0x140000e6150 Type:5 DataAtom: Data:html Namespace: Attr:[]}
what do you expect to see
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
where is the *url.URL?
*url.URL implement fmt.Stringer, its string representation should be printed.
you need to walk the tree, doc is the parsed html.
do you expect it to recursively follow the pointer?
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
think about linked list. but instead of pointers to prev and next element, you have Parent, FirstChild, LastChild, PrevSibling, NextSibling.
How that’s mean i can’t saw the whole thing if i didn’t walk the three ?
why do you want to see it?
Honestly I just tried to *doc.firstchild et view the content but i get another pointer and get surprised i though i could see the whole picture
The entire node like the image i sent
And then walk the three to get what i wanna get