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) } }
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) } }
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()}) }
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) }