func (self *HttpDownloader) downloadJson(p *context.Response, req *context.Request) *context.Response { var err error p, destbody := self.downloadFile(p, req) if !p.IsSucc() { return p } var body []byte body = []byte(destbody) mtype := req.GetRespType() if mtype == "jsonp" { tmpstr := util.JsonpToJson(destbody) body = []byte(tmpstr) } var r *simplejson.Json if r, err = simplejson.NewJson(body); err != nil { reporter.Log.Println(string(body) + "\t" + err.Error()) p.SetStatus(true, err.Error()) return p } // json result p.SetBodyStr(string(body)).SetJson(r).SetStatus(false, "") return p }
func (self *HttpDownloader) downloadHtml(p *context.Response, req *context.Request) *context.Response { var err error p, destbody := self.downloadFile(p, req) //fmt.Printf("Destbody %v \r\n", destbody) if !p.IsSucc() { //fmt.Print("Response error \r\n") return p } bodyReader := bytes.NewReader([]byte(destbody)) var doc *goquery.Document if doc, err = goquery.NewDocumentFromReader(bodyReader); err != nil { reporter.Log.Println(err.Error()) p.SetStatus(true, err.Error()) return p } var body string if body, err = doc.Html(); err != nil { reporter.Log.Println(err.Error()) p.SetStatus(true, err.Error()) return p } p.SetBodyStr(body).SetHtmlParser(doc).SetStatus(false, "") return p }
func (self *HttpDownloader) downloadText(p *context.Response, req *context.Request) *context.Response { p, destbody := self.downloadFile(p, req) if !p.IsSucc() { return p } p.SetBodyStr(destbody).SetStatus(false, "") return p }