opengraph

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 16, 2021 License: MIT Imports: 4 Imported by: 3

README

opengraph

Build Status Go Reference Go Report Card

ogp

opengraph is a Go library and command-line tool for extracting Open Graph metadata from HTML documents.

Library

Install
import "github.com/johnreutersward/opengraph"
Usage

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 ...
...

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

Documentation

Overview

Package opengraph extracts Open Graph metadata from HTML documents. See http://ogp.me/ for more information about the Open Graph protocol.

Usage:

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 ...
...

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MetaData

type MetaData struct {
	Property string // Property attribute without prefix.
	Content  string // Content attribute. See http://ogp.me/#data_types for a list of content attribute types.
	Prefix   string
}

func Extract

func Extract(doc io.Reader) ([]MetaData, error)

Extract extracts Open Graph metadata from a HTML document. If no relevant metadata is found the result will be empty. The input is assumed to be UTF-8 encoded.

func ExtractPrefix

func ExtractPrefix(doc io.Reader, prefix string) ([]MetaData, error)

Same as Extract but extracts metadata with a specific prefix, e.g. "fb" for Facebook. If prefix is empty all matching metadata is extracted.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL