shad-go/lectures/01-basics/countwords/main.go

28 lines
449 B
Go
Raw Normal View History

2020-02-20 14:40:51 +00:00
package main
import (
"fmt"
"net/http"
"golang.org/x/net/html"
)
func CountWordsAndImages(url string) (words, images int, err error) {
resp, err := http.Get(url)
if err != nil {
return
}
doc, err := html.Parse(resp.Body)
resp.Body.Close()
if err != nil {
err = fmt.Errorf("parsing HTML: %s", err)
return
}
words, images = countWordsAndImages(doc)
return
}
func countWordsAndImages(n *html.Node) (words, images int) {
return
}