mirror of
https://github.com/MontFerret/ferret.git
synced 2025-01-06 03:03:57 +02:00
Replaced Document with Page HTLM struct in Pagination helper function (#448)
This commit is contained in:
parent
89320eef66
commit
453ba932eb
1
go.sum
1
go.sum
@ -61,6 +61,7 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible h1:4QJd3OLAMgj7ph+yZTuX13Ld4UpgHp07nNdFX7mqFfM=
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible/go.mod h1:Wi9p2TTF5DG5oU+6YfsmYQpsTIOm0B1VNzQg9Mw6nPk=
|
||||
github.com/ngdinhtoan/glide-cleanup v0.2.0/go.mod h1:UQzsmiDOb8YV3nOsCxK/c9zPpCZVNoHScRE3EO9pVMM=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
@ -21,7 +21,7 @@ func Pagination(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
return values.None, err
|
||||
}
|
||||
|
||||
doc, err := drivers.ToDocument(args[0])
|
||||
page, err := drivers.ToPage(args[0])
|
||||
|
||||
if err != nil {
|
||||
return values.None, err
|
||||
@ -35,19 +35,19 @@ func Pagination(_ context.Context, args ...core.Value) (core.Value, error) {
|
||||
|
||||
selector := args[1].(values.String)
|
||||
|
||||
return &Paging{doc, selector}, nil
|
||||
return &Paging{page, selector}, nil
|
||||
}
|
||||
|
||||
var PagingType = core.NewType("paging")
|
||||
|
||||
type (
|
||||
Paging struct {
|
||||
document drivers.HTMLDocument
|
||||
page drivers.HTMLPage
|
||||
selector values.String
|
||||
}
|
||||
|
||||
PagingIterator struct {
|
||||
document drivers.HTMLDocument
|
||||
page drivers.HTMLPage
|
||||
selector values.String
|
||||
pos values.Int
|
||||
}
|
||||
@ -82,7 +82,7 @@ func (p *Paging) Copy() core.Value {
|
||||
}
|
||||
|
||||
func (p *Paging) Iterate(_ context.Context) (core.Iterator, error) {
|
||||
return &PagingIterator{p.document, p.selector, -1}, nil
|
||||
return &PagingIterator{p.page, p.selector, -1}, nil
|
||||
}
|
||||
|
||||
func (i *PagingIterator) Next(ctx context.Context) (core.Value, core.Value, error) {
|
||||
@ -92,7 +92,7 @@ func (i *PagingIterator) Next(ctx context.Context) (core.Value, core.Value, erro
|
||||
return values.ZeroInt, values.ZeroInt, nil
|
||||
}
|
||||
|
||||
exists, err := i.document.ExistsBySelector(ctx, i.selector)
|
||||
exists, err := i.page.GetMainFrame().ExistsBySelector(ctx, i.selector)
|
||||
|
||||
if err != nil {
|
||||
return values.None, values.None, err
|
||||
@ -102,7 +102,7 @@ func (i *PagingIterator) Next(ctx context.Context) (core.Value, core.Value, erro
|
||||
return values.None, values.None, core.ErrNoMoreData
|
||||
}
|
||||
|
||||
err = i.document.GetElement().ClickBySelector(ctx, i.selector, 1)
|
||||
err = i.page.GetMainFrame().GetElement().ClickBySelector(ctx, i.selector, 1)
|
||||
|
||||
if err != nil {
|
||||
return values.None, values.None, err
|
||||
|
Loading…
Reference in New Issue
Block a user