Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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.
- Host: GitHub
- URL: https://github.com/conneroisu/seltabl
- Owner: conneroisu
- License: mit
- Created: 2024-06-02T17:24:34.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-09-09T18:58:45.000Z (2 months ago)
- Last Synced: 2024-11-15T07:33:06.980Z (5 days ago)
- Topics: cli, code-generation, golang, golang-library, golang-package, golang-tools, goquery, html, jquery, scrap, scraper
- Language: Go
- Homepage:
- Size: 186 MB
- Stars: 4
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
# seltabl
![seltabl logo](/assets/avatar.png)
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
```## Usage
```go
package mainimport (
"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)