A golang command line utility and library to extract JSON-LD data embedded in HTML.
go get github.com/daetal-us/getld
Note: results are always returned as an array.
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.
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)) // [...]
}