Go implementation of https://ogp.me/
package main
import (
"fmt"
"github.com/otiai10/opengraph/v2"
)
func main() {
ogp, err := opengraph.Fetch("https://github.com/")
fmt.Println(ogp, err)
}
% go get github.com/otiai10/opengraph/ogp
% ogp --help
% ogp -A otiai10.com
Just for fun 😉
Set an option for fetching:
intent := opengraph.Intent{
Context: ctx,
HTTPClient: client,
Strict: true,
TrustedTags: []string{"meta", "title"},
}
ogp, err := opengraph.Fetch("https://ogp.me", intent)
Use any io.Reader
as a data source:
f, _ := os.Open("my_test.html")
defer f.Close()
ogp := &opengraph.OpenGraph{}
err := ogp.Parse(f)
or if you already have parsed *html.Node
:
err := ogp.Walk(node)
Do you wanna make absolute URLs?:
ogp.Image[0].URL // /logo.png
ogp.ToAbs()
ogp.Image[0].URL // https://ogp.me/logo.png