opengraph is a Go library and command-line tool for extracting Open Graph metadata from HTML documents.
import "github.com/johnreutersward/opengraph"
To extract Open Graph metadata from a movie on IMDb (sans error handling)
res, _ := http.Get("http://www.imdb.com/title/tt0118715/")
md, _ := opengraph.Extract(res.Body)
for i := range md {
fmt.Printf("%s = %s\n", md[i].Property, md[i].Content)
}
Which will output
url = http://www.imdb.com/title/tt0118715/
type = video.movie
title = The Big Lebowski (1998)
site_name = IMDb
description = Directed by Joel Coen, Ethan Coen. With Jeff Bridges ...
...
Binary releases:
https://github.com/johnreutersward/opengraph/releases
Or build from source:
$ go get github.com/johnreutersward/opengraph/cmd/opengraph
$ opengraph http://www.imdb.com/title/tt0118715/
type: video.movie
title: The Big Lebowski (1998)
site_name: IMDb
...
Output in JSON:
$ opengraph -json http://www.imdb.com/title/tt0118715/
[
{
"Property": "type",
"Content": "video.movie",
"Prefix": "og"
},
{
"Property": "title",
"Content": "The Big Lebowski (1998)",
"Prefix": "og"
},
{
"Property": "site_name",
"Content": "IMDb",
"Prefix": "og"
},
...
]
MIT