25 lines
430 B
Go
25 lines
430 B
Go
package scraper
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
"strings"
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
|
)
|
|
|
|
func GetText(resp *http.Response) (string, error) {
|
|
defer resp.Body.Close()
|
|
body, err := io.ReadAll(resp.Body)
|
|
return string(body), err
|
|
}
|
|
|
|
func GetHtml(resp *http.Response) (*goquery.Document, error) {
|
|
text, err := GetText(resp)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return goquery.NewDocumentFromReader(strings.NewReader(text))
|
|
}
|