Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/conneroisu/seltabl

golang library for parsing html tables into stucts leveraging goquery to be configurable with useful developer tooling including a language server.
https://github.com/conneroisu/seltabl

cli code-generation golang golang-library golang-package golang-tools goquery html jquery scrap scraper

Last synced: about 5 hours ago
JSON representation

golang library for parsing html tables into stucts leveraging goquery to be configurable with useful developer tooling including a language server.

Awesome Lists containing this project

README

        

# seltabl

![seltabl logo](/assets/avatar.png)


go.dev
Build Status

Go Report Card

A golang library with accompanying cli and language server for configurably parsing html sequences into stucts originally built for html tables, but can be used for any html sequence.

Enables data binding to structs and provides a simple, but dynamic way to define a table schema.

## Installation

Install the package in a project with:

```bash
go get github.com/conneroisu/seltabl
```

Install the [cli](https://github.com/conneroisu/seltabl/tree/main/tools/seltabls) containing the language server operating over the [ lsp ](https://microsoft.github.io/language-server-protocol/) protocol and package command line utilities with:

```bash
go install github.com/conneroisu/seltabl/tools/seltabls@latest
```

Recording of Language Server

## Usage

```go
package main

import (
"fmt"
"github.com/conneroisu/seltabl"
"github.com/conneroisu/seltabl/testdata"
)

type TableStruct struct {
A string `json:"a" hSel:"tr:nth-child(1) td:nth-child(1)" dSel:"tr td:nth-child(1)" ctl:"text"`
B string `json:"b" hSel:"tr:nth-child(1) td:nth-child(2)" dSel:"tr td:nth-child(2)" ctl:"text"`
}

var fixture = `


a
b


1
2


3
4


5
6


7
8

`

func main() {
fss, err := seltabl.NewFromString[TableStruct](fixture)
if err != nil {
panic(fmt.Errorf("failed to parse html: %w", err))
}
for _, fs := range fss {
fmt.Printf("%+v\n", fs)
}
}
```

Output:

```bash
{A:1 B:2}
{A:3 B:4}
{A:5 B:6}
{A:7 B:8}
```

## Development

A makefile at the root of the project is provided to help with development.

### Testing

One can run the tests with:
```bash
make test
```

### Linting

One can run the linter with:
```bash
make lint
```

### Formatting

One can run the formatter with:
```bash
make fmt
```

### Generating documentation

One can run the documentation generator with:
```bash
make doc
```

## License

MIT

Types of ctl selectors:

- text (default) (queries the text of the selected element)
- spaces (queries the text of the selected element split by spaces)
- query (queries the attributes of the selected elemente)