Skip to content
/ ski Public

ski is a tool for extracting structured data from websites using extensible YAML syntax rules.

License

Notifications You must be signed in to change notification settings

shiroyk/ski

Repository files navigation

ski

GitHub go.mod Go version Go Report Card GitHub
ski is a tool written in Golang for extracting structured data.

Usage

package main

import (
	"context"
	"encoding/json"
	"io"
	"net/http"
	"os"
	"time"

	"github.com/shiroyk/ski"
)

func main() {
	const source = `
$gq.elements: table[aria-labelledby="folders-and-files"] .react-directory-row-name-cell-large-screen .react-directory-filename-cell a
$each:
  $map:
    title:
      $gq: -> text
    href:
      $gq: -> href
    
`
	executor, err := ski.Compile(source)
	if err != nil {
		panic(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
	defer cancel()

	resp, err := http.Get("https://github.com/shiroyk/ski")
	if err != nil {
		panic(err)
	}
	defer resp.Body.Close()

	bytes, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}

	result, err := executor.Exec(ctx, string(bytes))
	if err != nil {
		panic(err)
	}

	err = json.NewEncoder(os.Stdout).Encode(result)
	if err != nil {
		panic(err)
	}
}

License

ski is distributed under the MIT license.

About

ski is a tool for extracting structured data from websites using extensible YAML syntax rules.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages