You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »


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

ReferenceURL
Find out how to scrape HTML tables with Golanghttps://www.webscrapingapi.com/find-out-how-to-scrape-html-tables-with-golang


  • No labels