scraping helper
This commit is contained in:
24
internal/scraper/helper.go
Normal file
24
internal/scraper/helper.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
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))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user