https://github.com/mkfsn/crepe
https://github.com/mkfsn/crepe
golang goquery jquery struct-tag
Last synced: 24 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mkfsn/crepe
- Owner: mkfsn
- Created: 2020-02-29T02:59:08.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-08T12:37:18.000Z (over 6 years ago)
- Last Synced: 2025-01-22T04:21:37.214Z (over 1 year ago)
- Topics: golang, goquery, jquery, struct-tag
- Language: Go
- Homepage: https://godoc.org/github.com/mkfsn/crepe
- Size: 22.5 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
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)
```