示例#1
0
文件: finder_test.go 项目: zackb/code
func Test_Vimeo(t *testing.T) {
	g, err := grab.GrabUrl("http://vimeo.com/66480704")
	if err != nil {
		t.Error(err.Error())
	}
	v := GrabVideo(g)
	if v.Title != "Genesis" {
		t.Error("wrong title", v.Title)
	}
}
示例#2
0
文件: finder_test.go 项目: zackb/code
func Test_YouTube(t *testing.T) {
	g, err := grab.GrabUrl("http://www.youtube.com/watch?v=f6kdp27TYZs")
	if err != nil {
		t.Error(err.Error())
	}
	v := GrabVideo(g)
	if v.Title != "Google I/O 2012 - Go Concurrency Patterns" {
		t.Error("wrong title", v.Title)
	}
}
示例#3
0
文件: web.go 项目: zackb/code
func doGrab(w http.ResponseWriter, req *http.Request) {
	url := req.FormValue("u")
	grab, _ := grab.GrabUrl(url)
	for k, v := range grab.Html.Meta {
		log.Println("Meta: " + k + " = " + v)
	}

	for k, v := range grab.Headers {
		log.Println("Header: " + k + " = " + v)
	}

	log.Println("Summary: " + grab.Summary())

	w.Header().Set("Content-Type", "application/json")
	fmt.Fprint(w, JsonResponse{"item": grab.Item()})
}
示例#4
0
文件: main.go 项目: zackb/code
func handle(url string) {
	g, err := grab.GrabUrl(url)
	if err != nil {
		fmt.Println("Error: ", err)
		return
	}
	//crawl.Crawl(g)
	for k, v := range g.Html.Meta {
		fmt.Println("Meta: " + k + " = " + v)
	}
	for k, v := range g.Headers {
		fmt.Println("Header: " + k + " = " + v)
	}
	fmt.Printf("Json: %v\n", g.Json)
	fmt.Printf("Summary: %v\n", g.Summary())
	//fmt.Printf("Paragraphs: %d %v\n", len(g.Html.Paragraphs), g.Html.Paragraphs)
}