<p>I'm writing an XDA scraper for fun, to learn yhat'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: "fmt"
./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've fixed all these errors in my code -- and I'm not sure why I'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'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'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't changed the code since I posted this -- compiler errors annoy me more than small children on airplanes, so I'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 "file in editor is a different one from the one compiled", for example because you moved your code but didn't reopen the file in the editor (so it will write to the old location).</p></pre>ecmdome: <pre><p>I'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, "href")
fmt.Println(href)
}
</code></pre>
<p>Is going to return the INDEX of the range in "thread", not the "thread" itself.</p></pre>weberc2: <pre><p>How are you building/running this? (e.g., <code>go run <file>.go</code> or <code>go install <pkg></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't. a) your code can lie outside GOPATH without any problems, you just can'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 'l' file</code> to show non printable characters.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传