mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-16 11:37:36 +02:00
5620be211c
* Renamed DOCUMENT to PAGE * Added PageLoadParams * Added PageLoadParams * Renamed LoadPageParams -> PageLoadParams * Added support for context.Done() (#201) * Bug/#189 operators precedence (#202) * Fixed math operators precedence * Fixed logical operators precedence * Fixed array operator * Added support for parentheses to enforce a different operator evaluation order * Feature/#200 drivers (#209) * Added new interfaces * Renamed dynamic to cdp driver * Renamed drivers * Added ELEMENT_EXISTS function (#210) * Renamed back PAGE to DOCUMENT (#211) * Added Getter and Setter interfaces
57 lines
1.0 KiB
Go
57 lines
1.0 KiB
Go
package http
|
|
|
|
import (
|
|
"github.com/MontFerret/ferret/pkg/runtime/core"
|
|
"github.com/MontFerret/ferret/pkg/runtime/values"
|
|
"github.com/PuerkitoBio/goquery"
|
|
)
|
|
|
|
type HTMLDocument struct {
|
|
*HTMLElement
|
|
url values.String
|
|
}
|
|
|
|
func NewHTMLDocument(
|
|
url string,
|
|
node *goquery.Document,
|
|
) (*HTMLDocument, error) {
|
|
if url == "" {
|
|
return nil, core.Error(core.ErrMissedArgument, "document url")
|
|
}
|
|
|
|
if node == nil {
|
|
return nil, core.Error(core.ErrMissedArgument, "document root selection")
|
|
}
|
|
|
|
el, err := NewHTMLElement(node.Selection)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &HTMLDocument{el, values.NewString(url)}, nil
|
|
}
|
|
|
|
func (doc *HTMLDocument) Type() core.Type {
|
|
return core.HTMLDocumentType
|
|
}
|
|
|
|
func (doc *HTMLDocument) Compare(other core.Value) int {
|
|
switch other.Type() {
|
|
case core.HTMLDocumentType:
|
|
otherDoc := other.(values.HTMLDocument)
|
|
|
|
return doc.url.Compare(otherDoc.URL())
|
|
default:
|
|
if other.Type() > core.HTMLDocumentType {
|
|
return -1
|
|
}
|
|
|
|
return 1
|
|
}
|
|
}
|
|
|
|
func (doc *HTMLDocument) URL() core.Value {
|
|
return doc.url
|
|
}
|