<p>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:</p>
<p><a href="https://play.golang.org/p/nq1LqG2Vo7k" rel="nofollow">https://play.golang.org/p/nq1LqG2Vo7k</a></p>
<p>Output:</p>
<p><a href="https://i.redd.it/xuzlx25qbkc11.png" rel="nofollow">https://i.redd.it/xuzlx25qbkc11.png</a></p>
<p>However, when I try to separate the code into a separate package there seem to be some kind of an error. Code:</p>
<p><a href="https://play.golang.org/p/4yJ61ftz9rY" rel="nofollow">https://play.golang.org/p/4yJ61ftz9rY</a></p>
<p>and the associated "parser" package:</p>
<p><a href="https://play.golang.org/p/TTAUDuuShwH" rel="nofollow">https://play.golang.org/p/TTAUDuuShwH</a></p>
<p>Output:</p>
<p><a href="https://i.redd.it/7qdw6mxqckc11.png" rel="nofollow">https://i.redd.it/7qdw6mxqckc11.png</a></p>
<p>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.</p>
<p>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.</p>
<p>Thank you SO much in advance for taking the time to look at this.</p>
<hr/>**评论:**<br/><br/>9nut: <pre><p>in parser.go</p>
<p>for c := n.FirstChild; c != nil; c = n.NextSibling </p>
<p>in main.go</p>
<p>for c := n.FirstChild; c != nil; c = c.NextSibling</p>
<p>parser.go should be c = c.NextSibling</p></pre>ODAwake: <pre><p>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! </p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传