Skip to content

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

License

Notifications You must be signed in to change notification settings

daetal-us/getld

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)) // [...]
}

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages