diff --git a/function.go b/function.go index c457982..1776f8d 100644 --- a/function.go +++ b/function.go @@ -224,7 +224,7 @@ func (builtin BuiltinFunctions) Eq(node *goquery.Selection, args ...string) (out // eqAndAttr(index, name) reduces the set of matched elements to the one at the specified index, and attr() return string. func (builtin BuiltinFunctions) EqAndAttr(node *goquery.Selection, args ...string) (out interface{}, err error) { if len(args) <= 1 { - return "", fmt.Errorf("eq(index) must has index") + return "", fmt.Errorf("eq(index) must has index and attr name") } indexValue := strings.TrimSpace(args[0]) idx, err := strconv.Atoi(indexValue) @@ -237,7 +237,7 @@ func (builtin BuiltinFunctions) EqAndAttr(node *goquery.Selection, args ...strin // eqAndHtml(index) reduces the set of matched elements to the one at the specified index, and html() return string. func (builtin BuiltinFunctions) EqAndHtml(node *goquery.Selection, args ...string) (out interface{}, err error) { - if len(args) <= 1 { + if len(args) <= 0 { return "", fmt.Errorf("eq(index) must has index") } indexValue := strings.TrimSpace(args[0]) @@ -250,7 +250,7 @@ func (builtin BuiltinFunctions) EqAndHtml(node *goquery.Selection, args ...strin // eqAndOutHtml(index) reduces the set of matched elements to the one at the specified index, and outHtml() return string. func (builtin BuiltinFunctions) EqAndOutHtml(node *goquery.Selection, args ...string) (out interface{}, err error) { - if len(args) <= 1 { + if len(args) <= 0 { return "", fmt.Errorf("eq(index) must has index") } indexValue := strings.TrimSpace(args[0]) diff --git a/pagser_test.go b/pagser_test.go index e116dff..d266d34 100644 --- a/pagser_test.go +++ b/pagser_test.go @@ -29,6 +29,10 @@ type PageData struct { NavEachHtml []string `pagser:".navlink li->eachHtml()"` NavEachOutHtml []string `pagser:".navlink li->eachOutHtml()"` NavJoinString string `pagser:".navlink li->eachJoin(|)"` + NavEq string `pagser:".navlink li->eq(1)"` + NavEqAttr string `pagser:".navlink li->eqAndAttr(1, id)"` + NavEqHtml string `pagser:".navlink li->eqAndHtml(1)"` + NavEqOutHtml string `pagser:".navlink li->eqAndOutHtml(1)"` WordsSplitArray []string `pagser:".words->split(|)"` Value string `pagser:"input[name='feedback']->value()"` SubPageData *SubPageData `pagser:".navlink li:last-child"`