getld

command module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2018 License: MIT Imports: 5 Imported by: 0

README

getld

A golang command line utility and library to extract JSON-LD data embedded in HTML.

Installation

go get github.com/daetal-us/getld

Usage

Note: results are always returned as an array.

Command Line

Retrieve JSON-LD data embedded in HTML from a remote source:

getld http://apple.com

Retrieve JSON-LD data embedded in HTML from multiple remote sources:

getld http://apple.com http://adobe.com

Note: results from multiple remote sources are combined into a single array.

Golang
package main

import (
	"log"
	"encoding/json"

	"github.com/daetal-us/getld/extract"
)

func main() {
	extractFromHTML()
	extractFromURL()
}

func extractFromHTML() {
	html := `<html><body><script type="application/json+ld>{"@type":"organization","name":"example"}</script></body></html>"`
	results, err := extract.FromHTML(html)
	if err != nil {
		log.Fatal(err)
	}
	encoded, err := json.Marshal(results)
	if err != nil {
		log.fatal(err)
	}
	log.Println(string(encoded)) // [{"@type":"organization","name":"example"}]
}

func extractFromURL() {
	results, err := extract.FromURL("http://apple.com")
	if err != nil {
		log.Fatal(err)
	}
	encoded, err := json.Marshal(results)
	if err != nil {
		log.fatal(err)
	}
	log.Println(string(encoded)) // [...]
}

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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