Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/mkfsn/crepe


https://github.com/mkfsn/crepe

golang goquery jquery struct-tag

Last synced: about 1 month ago
JSON representation

Awesome Lists containing this project

README

        

# crepe

crepe is a tool that helps you extract the data from ~~tons-of-layers~~ HTML in an easier way.

This uses a brilliant project called [goquery](https://github.com/PuerkitoBio/goquery) to extract the data.

# Example

By specifying some selectors in struct tags, crepe helps you unmarshal the data from HTML.

```go
html := `


Employees







Tony
Male
20


Mary
Female
23



`
var data struct {
Title string `crepe:"div#header>h1,text"`
Employees []*struct {
Id string `crepe:"attr=data-id"`
Name string `crepe:"td,:eq(0),text"`
Gender string `crepe:"td,:eq(1),text"`
Age int `crepe:"td,:eq(2),text"`
Role string `crepe:"attr=role"`
} `crepe:"table,:last,tbody>tr"`
}
if err := Unmarshal([]byte(html), &data); err != nil {
fmt.Printf("error: %v\n", err)
return
}
fmt.Printf("result: %v\n", data)
```