Reading in a webpage
package main import ( "fmt" "io/ioutil" "log" "net/http" ) func main() { resp, err := http.Get("https://www.w3schools.com/html/html_tables.asp") if err != nil { log.Fatal(err) } defer resp.Body.Close() // Read the response body and convert it to a string body, err := ioutil.ReadAll(resp.Body) if err != nil { log.Fatal(err) } html := string(body) fmt.Println(html) }
Install goquery
go get github.com/PuerkitoBio/goquery
Now Read in the response body into goquery
doc, err := goquery.NewDocumentFromReader(resp.Body) if err != nil { log.Fatal(err) }
References
Reference | URL |
---|---|
Find out how to scrape HTML tables with Golang | https://www.webscrapingapi.com/find-out-how-to-scrape-html-tables-with-golang |