https://github.com/johnreutersward/opengraph
opengraph is a Go library and command-line tool for extracting Open Graph metadata from HTML documents
https://github.com/johnreutersward/opengraph
opengraph
Last synced: about 1 year ago
JSON representation
opengraph is a Go library and command-line tool for extracting Open Graph metadata from HTML documents
- Host: GitHub
- URL: https://github.com/johnreutersward/opengraph
- Owner: johnreutersward
- License: mit
- Created: 2014-07-06T12:35:47.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2021-01-16T12:21:08.000Z (over 5 years ago)
- Last Synced: 2024-11-21T18:42:39.623Z (over 1 year ago)
- Topics: opengraph
- Language: Go
- Homepage: https://pkg.go.dev/github.com/johnreutersward/opengraph
- Size: 39.1 KB
- Stars: 29
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# opengraph
[](https://travis-ci.org/johnreutersward/opengraph)
[](https://pkg.go.dev/github.com/johnreutersward/opengraph)
[](https://goreportcard.com/report/github.com/johnreutersward/opengraph)

> opengraph is a Go library and command-line tool for extracting [Open Graph](https://ogp.me/ "Open Graph protocol") metadata from HTML documents.
## Library
### Install
```go
import "github.com/johnreutersward/opengraph"
```
### Usage
To extract Open Graph metadata from a movie on IMDb (sans error handling)
```go
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 ...
...
```
## Command-line tool
### Install
Binary releases:
https://github.com/johnreutersward/opengraph/releases
Or build from source:
```
$ go get github.com/johnreutersward/opengraph/cmd/opengraph
```
### Usage
```
$ 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"
},
...
]
```
## License
MIT