func (self *Client) RespToDoc(resp *http.Response) (*goquery.Document, error) { var reader io.Reader = resp.Body var err error if self.Encoding != "utf-8" { buf := new(bytes.Buffer) io.Copy(buf, resp.Body) runes, err := rune_conv.From(self.Encoding, buf.Bytes()) if err != nil { return nil, err } reader = bytes.NewReader([]byte(string(runes))) } node, err := html.Parse(reader) if err != nil { print("here\n") return nil, err } resp.Body.Close() return goquery.NewDocumentFromNode(node), nil }
func (self *Client) GetDoc(url string) (*goquery.Document, error) { resp, err := self.Get(url) if err != nil { return nil, err } var reader io.Reader = resp.Body if self.Encoding != "utf-8" { buf := new(bytes.Buffer) io.Copy(buf, resp.Body) runes, err := From(self.Encoding, buf.Bytes()) if err != nil { return nil, err } reader = bytes.NewReader([]byte(string(runes))) } node, err := html.Parse(reader) if err != nil { return nil, err } resp.Body.Close() return goquery.NewDocumentFromNode(node), nil }