schemata

package module
v0.0.0-...-9a5ed59 Latest Latest
Warning

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

Go to latest
Published: Feb 13, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

README

WIP Schema.org parser (using Goquery)

schemata/microdata allows you extract microdata from goquery.Documents

package main

import (
	"fmt"
	"log"
	"net/http"
	"os"

	"github.com/AltayAkkus/schemata/microdata"
	"github.com/PuerkitoBio/goquery"
)


func main() {
	if len(os.Args) != 2 {
		log.Fatalf("%s <url>", os.Args[0])
		return
	}
	url := os.Args[1]
	log.Printf("GET'ting %s", url)
	res, err := http.Get(url)
	if err != nil {
		log.Fatal("Failed to GET")
	}
	defer res.Body.Close()
	doc, err := goquery.NewDocumentFromReader(res.Body)
	if err != nil {
		log.Fatal("Could not read body into document")
	}

	schemas := microdata.Extract(doc)
	// print to console
	for _, schema := range schemas {
		fmt.Println(schema.JSON())
	}
}

There is also a JSON-LD extractor at schemata/jsonld but JSON-LD parsing is not implemented yet,

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DebugJSON

func DebugJSON(schemas []Schema) string

DebugJSON converts a slice of schemas to formatted JSON string for debugging

Types

type Schema

type Schema struct {
	Element    goquery.Selection `json:"-"`
	Type       string
	Source     Source
	RawMessage json.RawMessage
}

func (*Schema) JSON

func (s *Schema) JSON() string

JSON converts the schema to a formatted JSON string for debugging

type Source

type Source string
const (
	JSON_LD   Source = "json-ld"
	Microdata Source = "microdata"
)

Directories

Path Synopsis
cmd
schemata command

Jump to

Keyboard shortcuts

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