Simple HTML parser and data fetcher library written on Golang under MIT License.
- Golang (version >= 1.20)
- golang.org/x/net
go get github.com/wmentor/html
package main
import (
"fmt"
"time"
"github.com/wmentor/html"
)
func main() {
src := "https://edition.cnn.com"
parser := html.New()
opts := &html.GetOpts{
Agent:"Mozilla/5.0 (compatible; MSIE 10.0)",
Timeout: time.Second*60,
}
parser.Get(src,opts)
fmt.Println( string(parser.Text()) )
parser.EachLink(func(link string) {
fmt.Println("url=" + link)
} )
parser.EachImage(func(link string) {
fmt.Println("img=" + link)
} )
parser.EachIframe(func(link string) {
fmt.Println("iframe=" + link)
} )
}
package main
import (
"fmt"
"os"
"github.com/wmentor/html"
)
func main() {
parser := html.New()
parser.Parse(os.Stdin) // io.Reader
fmt.Println( string(parser.Text()) )
parser.EachLink(func(link string) {
fmt.Println("url=" + link)
} )
parser.EachImage(func(link string) {
fmt.Println("img=" + link)
} )
parser.EachIframe(func(link string) {
fmt.Println("iframe=" + link)
} )
}