Can someone please explain why my code keeps getting errors?

blov · · 880 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I&#39;m writing an XDA scraper for fun, to learn yhat&#39;s scrape library. </p> <p>When I run my code, I get the following errors:</p> <pre><code># command-line-arguments ./xdaparser.go:6: imported and not used: &#34;fmt&#34; ./xdaparser.go:29: undefined: threads ./xdaparser.go:42: cannot use root (type *html.Node) as type html.Node in return argument ./xdaparser.go:47: cannot convert nil to type atom.Atom ./xdaparser.go:50: missing return at end of function ./xdaparser.go:51: missing return at end of function </code></pre> <p>However, I&#39;ve fixed all these errors in my code -- and I&#39;m not sure why I&#39;m getting an fmt unused error. <a href="http://pastebin.com/LxNTFtbf" rel="nofollow">Here is my code</a>; can someone please tell me what I&#39;m doing wrong before I go insane? </p> <hr/>**评论:**<br/><br/>sajal: <pre><p>i dont get the unused fmt... moreover your import fmt is at line 18 and not 6 . Can you post your latest code and its corresponding error?</p></pre>ecmdome: <pre><p>Yeah it seems as if he might be running the wrong code?</p> <p>Check your GOPATH. Also how are you running this? go run?</p></pre>crash_focus: <pre><p>I&#39;m running the code in a directory separate from my actual GOPATH -- would that be presenting a problem? </p></pre>sajal: <pre><p>no</p></pre>crash_focus: <pre><p>I haven&#39;t changed the code since I posted this -- compiler errors annoy me more than small children on airplanes, so I&#39;m taking a break for a little bit. </p></pre>sajal: <pre><blockquote> <p>./xdaparser.go:29: undefined: threads</p> </blockquote> <p>line 29 is :<br/> matcher := func(n *html.Node) bool {</p> <p>It still appears that the errors are not from the pasted code, can you recheck please. Also What command you use to run it? Whats your output of :- go version go env</p> <p>PS: I like Go compiler errors. They are very informative and point you in the right direction.</p></pre>TheMerovius: <pre><p>I agree with that diagnosis. This is an obvious case of &#34;file in editor is a different one from the one compiled&#34;, for example because you moved your code but didn&#39;t reopen the file in the editor (so it will write to the old location).</p></pre>ecmdome: <pre><p>I&#39;ve done this so many times.... </p></pre>caledh: <pre><p>Also, you realize that this: </p> <pre><code> for thread, _ := range threads { href := scrape.Attr(thread, &#34;href&#34;) fmt.Println(href) } </code></pre> <p>Is going to return the INDEX of the range in &#34;thread&#34;, not the &#34;thread&#34; itself.</p></pre>weberc2: <pre><p>How are you building/running this? (e.g., <code>go run &lt;file&gt;.go</code> or <code>go install &lt;pkg&gt;</code> etc?)</p></pre>caledh: <pre><p>Yep, moving it out of your GOPATH means it probably cannot find fmt.</p></pre>TheMerovius: <pre><p>No, it doesn&#39;t. a) your code can lie outside GOPATH without any problems, you just can&#39;t import anything outside of your GOPATH (by definition) and b) fmt has nothing to do with GOPATH, if anything it lies in GOROOT (but usually just the installation dir of your distribution package).</p></pre>caledh: <pre><p>Cool. Thanks for correcting that. I was mistaken.</p></pre>StonyPriapus: <pre><p>From my experience in other languages this could be due to some non printable character. Try copying and pasting it from pastebin.</p> <p>Otherwise, if you use vim <code>vim -b file</code> opens it in binary mode and shows non printable characters. Sed also allows you to do <code>sed -n &#39;l&#39; file</code> to show non printable characters.</p></pre>

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

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