Intermediate gopher: A weird run-time bug I can't find. net/html package.

blov · · 1700 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<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 &#34;net/html&#34; 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 &#34;parser&#34; 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&#39;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&#39;t figure out why the mapping breaks down after the first two nodes.</p> <p>Also, the &#34;wrong&#34; output remains whether I call &#34;parser.Dfs()&#34; function or use the &#34;parser.Extract()&#34; function from the package. I&#39;m 90% sure that the issue lies somewhere with the .Dfs function because that&#39;s where the debugger poops itself, but I can&#39;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&#39;t believe the level of frustration I&#39;ve been experiencing over the last few hours! </p></pre>

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

1700 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传