From 30fddcc73d83a215358505872ce9da2fc5eff37d Mon Sep 17 00:00:00 2001 From: Yo'av Moshe Date: Thu, 12 Sep 2024 23:09:36 +0200 Subject: [PATCH] flatten results --- cmd/pipet/main.go | 1 + parsers/html.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/cmd/pipet/main.go b/cmd/pipet/main.go index d337137..d4b1024 100644 --- a/cmd/pipet/main.go +++ b/cmd/pipet/main.go @@ -125,6 +125,7 @@ func runPipet(c *cli.Context, specFile string) error { } log.Println("Generating output") + if jsonOutput { newValue = outputs.OutputJSON(pipet) } else if templateFile != "" { diff --git a/parsers/html.go b/parsers/html.go index d66a8ad..c2d5443 100644 --- a/parsers/html.go +++ b/parsers/html.go @@ -6,7 +6,7 @@ import ( "github.com/PuerkitoBio/goquery" ) -func ParseHTMLQueries(htmlData []byte, queries []string, nextPage string) (interface{}, string, error) { +func ParseHTMLQueries(htmlData []byte, queries []string, nextPage string) ([]interface{}, string, error) { result := []interface{}{} @@ -43,7 +43,13 @@ func ParseHTMLQueries(htmlData []byte, queries []string, nextPage string) (inter html = "" + html + "
" } value2, _, _ := ParseHTMLQueries([]byte(html), lines, "") - subresult = append(subresult, value2) + + if len(value2) == 1 { + subresult = append(subresult, value2[0]) + } else { + subresult = append(subresult, value2) + } + }) result = append(result, subresult)