microdata

package module
v0.0.0-...-310b1f6 Latest Latest
Warning

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

Go to latest
Published: May 6, 2015 License: BSD-2-Clause Imports: 8 Imported by: 0

README

Microdata

Microdata is a package for the Go programming language to extract HTML Microdata from HTML5 documents. It depends on the golang.org/x/net/html HTML5-compliant parser.

HTML Microdata is a markup specification often used in combination with the schema collection to make it easier for search engines to identify and understand content on web pages. One of the most common schema is the rating you see when you google for something. Other schemas are persons, places, events, products, etc.

Command Line

The command line utility returns a JSON object containing any items in the given HTML document.

Install:

$ go install github.com/namsral/microdata/cmd/microdata

Run:

$ microdata http://example.com/blogposting
{
  "items": [
    {
      "type": [
        "http://schema.org/BlogPosting"
      ],
      "properties": {
        "comment": [
          {
            "type": [
              "http://schema.org/UserComments"
            ],
            "properties": {
...

Library

package main

import (
	"encoding/json"
	"os"

	"github.com/namsral/microdata"
)

func main() {
	var data microdata.Microdata
	data, _ = microdata.ParseURL("http://example.com/blogposting")
	b, _ := json.MarshalIndent(data, "", "  ")
	os.Stdout.Write(b)
}

For documentation see godoc.org/github.com/namsral/microdata.

License

Copyright (c) 2015 Lars Wiegman. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item struct {
	Types      []string    `json:"type"`
	Properties PropertyMap `json:"properties"`
	Id         string      `json:"id,omitempty"`
}

func NewItem

func NewItem() *Item

NewItem returns a new Item.

type Microdata

type Microdata struct {
	Items []*Item `json:"items"`
}

func ParseHTML

func ParseHTML(r io.Reader, contentType string, u *url.URL) (*Microdata, error)

ParseHTML parses the HTML document available in the given reader and returns the microdata. The given url is used to resolve the URLs in the attributes. The given contentType is used convert the content of r to UTF-8.

func ParseURL

func ParseURL(urlStr string) (*Microdata, error)

ParseURL parses the HTML document available at the given URL and returns the microdata.

type PropertyMap

type PropertyMap map[string]ValueList

type ValueList

type ValueList []interface{}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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