【发布时间】:2014-12-20 00:48:43
【问题描述】:
我是 Go 新手,正在尝试编写一个简单的网络爬虫。我正在使用鸭鸭去的 api 并试图显示搜索结果。
这是我的代码 - 主包
import (
"fmt"
"net/http"
)
func main() {
getDuckDuckGo("food")
}
func getDuckDuckGo(keyword string) <- chan string{
resp, _ := http.Get("http://api.duckduckgo.com/?q=" + keyword + "&format=json&pretty=1")
c := make(chan string)
fmt.Println(resp)
var respMap map[string]interface{}
fmt.Println(respMap)
fmt.Println(respMap)
return c
}
我的 resp println 给了我这个 -
&{200 OK 200 HTTP/1.1 1 1 map[Connection:[keep-alive] Content-Type:[application/x-javascript] Date:[Sat, 20 Dec 2014 00:41:49 GMT] Cache-Control:[max-age=1] Expires:[Sat, 20 Dec 2014 00:41:50 GMT] Server:[nginx] X-Duckduckgo-Locale:[en_US]] 0xf840053c20 -1 [chunked] false map[] 0xf84007c000}
而不是任何 json。
我的 GET 请求是否正确?
【问题讨论】:
-
不要忽视你的错误!
-
我对其进行了编辑以克服 go 错误 - 但我仍然得到相同的响应......所以我不确定你的意思?
-
你的例子仍然没有对 http 响应做任何事情,并且打印了一个空的
respMap两次。