Lightweight metadata parser written in Go
With go-metaparser, you can easily extract structured meta-data from HTML. The purpose of this library is to be able to obtain all types of metadata from the web page.
Currently, it supports Open Graph, Twitter Card Metadata and some general metadata that doesn't belong to a particular type, for example - title, description etc.
Install the package with:
go get github.com/ammit/go-metaparser
Import it with:
import "github.com/ammit/go-metaparser"
and use parser as the package name inside the code.
Please check the example folder for details.
package main
import (
"fmt"
parser "github.com/ammit/go-metaparser"
)
const (
url = "http://ogp.me"
)
func main() {
p := parser.New()
b, err := p.FetchHTML(url)
if err != nil {
fmt.Printf("Could not fetch html from given url: %v \n", url)
}
defer b.Close()
err = p.ParseHTML(b)
fmt.Printf("The parsed title is: %v \n", p.Title)
}
You can run the benchmarks yourself, but here's the output on my machine:
BenchmarkParser-12 19024 62147 ns/op 9858 B/op 261 allocs/op
- Fork it (https://github.com/ammit/go-metaparser/fork)
- Create your feature branch (
git checkout -b feature/fooBar
) - Commit your changes (
git commit -am 'Add some fooBar'
) - Push to the branch (
git push origin feature/fooBar
) - Create a new Pull Request :)