2018-10-13 03:52:27 +02:00
|
|
|
package html
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2018-10-14 19:06:27 +02:00
|
|
|
|
2018-10-13 03:52:27 +02:00
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
|
|
)
|
|
|
|
|
2018-10-14 19:06:27 +02:00
|
|
|
// ElementsCount returns a number of found HTML elements by a given CSS selector.
|
|
|
|
// Returns an empty array if element not found.
|
2019-02-20 01:10:18 +02:00
|
|
|
// @param docOrEl (HTMLDocument|HTMLNode) - Parent document or element.
|
2018-10-14 19:06:27 +02:00
|
|
|
// @param selector (String) - CSS selector.
|
|
|
|
// @returns (Int) - A number of found HTML elements by a given CSS selector.
|
2019-02-21 04:24:05 +02:00
|
|
|
func ElementsCount(ctx context.Context, args ...core.Value) (core.Value, error) {
|
2018-10-13 03:52:27 +02:00
|
|
|
el, selector, err := queryArgs(args)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
return values.None, err
|
|
|
|
}
|
|
|
|
|
2019-09-07 03:02:41 +02:00
|
|
|
return el.CountBySelector(ctx, selector)
|
2018-10-13 03:52:27 +02:00
|
|
|
}
|