The goal for the code is to look at an HTML code and print out a list of the elements on the page. Most of the code is taken from the "net/html" package. So, this one works:
https://play.golang.org/p/nq1LqG2Vo7k
Output:
https://i.redd.it/xuzlx25qbkc11.png
However, when I try to separate the code into a separate package there seem to be some kind of an error. Code:
https://play.golang.org/p/4yJ61ftz9rY
and the associated "parser" package:
https://play.golang.org/p/TTAUDuuShwH
Output:
https://i.redd.it/7qdw6mxqckc11.png
I've been breaking my head against this the whole day testing, retesting, reading documentation, making sure the types were passed consistently, re-writing... nothing helped. I just can't figure out why the mapping breaks down after the first two nodes.
Also, the "wrong" output remains whether I call "parser.Dfs()" function or use the "parser.Extract()" function from the package. I'm 90% sure that the issue lies somewhere with the .Dfs function because that's where the debugger poops itself, but I can't figure out what causes it or how to go about fixing it.
Thank you SO much in advance for taking the time to look at this.
评论:
9nut:
ODAwake:in parser.go
for c := n.FirstChild; c != nil; c = n.NextSibling
in main.go
for c := n.FirstChild; c != nil; c = c.NextSibling
parser.go should be c = c.NextSibling
holy crap, man! GREAT eye! Thank you, thank you, thank you! I can go home and have a good weekend now! You won't believe the level of frustration I've been experiencing over the last few hours!
