Skip to content

linkosmos/tokeq

Repository files navigation

tokeq

Match & Callback iterator for html.Node - aimed for performance & HTML document reusability

Build Status GoDoc BSD3License

Benchmark

go test -run=10000 -bench=. -benchmem
Finding html

paragraph

operations time / operation Bytes / operation allocations / operation
BenchmarkGoQueryFindP 5000 277185 ns/op 46059 B/op 929 allocs/op
BenchmarkStandardLibraryTokenFindP 500 3698731 ns/op 291695 B/op 9240 allocs/op
BenchmarkStandardLibraryNodeFindP 20000 78340 ns/op 64 B/op 0 allocs/op
BenchmarkDissectNodesFindP 20000 68640 ns/op 64 B/op 0 allocs/op

Installation

go get github.com/linkosmos/tokeq

Godeps

godep get github.com/linkosmos/tokeq

Usage

package main

import (
	"fmt"
	"net/http"

	"github.com/linkosmos/tokeq"
	"golang.org/x/net/html"
)

func main() {
	response, err := http.Get("https://golang.org/pkg/fmt/")
	if err != nil {
		fmt.Printf("http.Get error: %s", err)
		return
	}

	err = tokeq.ParseResponseWithDefer(response, tokeq.Tok{
		Match: tokeq.MatchP,
		Callback: func(n *html.Node) {
			fmt.Println(tokeq.FindText(n))
		},
	})
	if err != nil {
		fmt.Printf("tokeq.ParseResponseWithDefer error: %s", err)
	}
}

Contributing

  1. Fork it ( https://github.com/linkosmos/tokeq/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add tokeq feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create a new Pull Request

About

Match & Callback iterator for html.Node - aimed for performance & HTML document reusability

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published