ski is a tool written in Golang for extracting structured data.
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)
}
}
ski is distributed under the MIT license.