Documentation
¶
Overview ¶
Package is is an infinite scroll processor using go-rod/rod(https://github.com/go-rod/rod).
Index ¶
Constants ¶
View Source
const (
Version = "v1.1.11"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IInfo ¶
type IInfo interface {
Matched() bool // Get matched bool value
MatchedStr() string // Get matched string value
SetMatched(matched bool) // Set matched bool value
SetMatchedStr(matchedStr string) // Set matched string value
String() string // Info struct to string
}
Interface for info struct
type IInfoList ¶
type IInfoList []IInfo
func (*IInfoList) Print ¶
func (list *IInfoList) Print(mode IInfoListPrintMode)
type IInfoListPrintMode ¶
type IInfoListPrintMode int8
const ( PrintAll IInfoListPrintMode = iota PrintMatched PrintUnmatched )
type InfoBase ¶
type InfoBase struct {
// contains filtered or unexported fields
}
IInfo base struct to be embedded
- Only String() should be overloaded
func (*InfoBase) SetMatchedStr ¶
Set matched string value
type Processor ¶ added in v1.0.0
type Processor struct {
*basestruct.Base
*Property
// Load [UrlStr] into [Page]
//
// No override needed.
LoadPage func() `json:"-"`
// Determine whether the scroll loop should continue running
//
// No override needed.
ScrollLoopBreak func(state *State) bool `json:"-"`
// Detect end of page, scroll no longer possible.
//
// No override needed.
//
// If elements are removed during [Run()], overload [V100_ExitScroll()] to do custom override.
// As both of following checks can be flawed if elements are removed from page DOM.
ScrollCalculation func(state *State) (scroll bool) `json:"-"`
// Use [MustScrollIntoView] on [element]
//
// No override needed.
ScrollElement func(element *rod.Element) `json:"-"`
// Return the container element.
//
// build-in behavior is to return [property.Container]
//
// Override if needed
V010_Container func() (container *rod.Element) `json:"-"`
// Return collection of repeating elements within [property.Page] or [property.Container]
//
// build-in behavior is to return `nil`
//
// **Must override**
V020_Elements func(container *rod.Element) *rod.Elements `json:"-"`
// Extract information from [element] and put into an [IInfo] structure and return it.
//
// build-in behavior is to return `nil`
//
// **Must override**
V030_ElementInfo func(element *rod.Element, index int) (info IInfo) `json:"-"`
// Determine [element] is a match or not base on [info]
//
// build-in behavior is to return (`true`, `""`)
//
// Override if needed
V040_ElementMatch func(element *rod.Element, index int, info IInfo) (matched bool, matchedStr string) `json:"-"`
// Do some processing (eg, print, write to file, db, etc) if [element] is a match
//
// build-in behavior is to do nothing
//
// Override if needed
V050_ElementProcessMatched func(element *rod.Element, index int, info IInfo) `json:"-"`
// Do some processing (eg, print, write to file, db, etc) if [element] is not a match
//
// build-in behavior is to do nothing
//
// Override if needed
V060_ElementProcessUnmatch func(element *rod.Element, index int, info IInfo) `json:"-"`
// Do some processing (eg, print, write to file, db, etc) regardless [element] is a match or not
//
// build-in behavior is to do nothing
//
// Override if needed
V070_ElementProcess func(element *rod.Element, index int, info IInfo) `json:"-"`
// Determine if an element is scrollable
//
// build-in behavior is to return `true“
//
// Override if needed
V080_ElementScrollable func(element *rod.Element, index int, info IInfo) bool `json:"-"`
// Do some processing if required
//
// build-in behavior is to do nothing
//
// Override if needed
V090_ElementLoopEnd func(element *rod.Element, index int, info IInfo) `json:"-"`
// Do some processing if required
//
// build-in behavior is to do nothing
//
// Override if needed
V100_ScrollLoopEnd func(state *State) `json:"-"`
}
IS processor structure
type Property ¶
type Property struct {
Page *rod.Page `json:"Page,omitempty"` // REQUIRED: Page element of [rod].
Container *rod.Element `json:"Container,omitempty"` // The outer most rod.Element containing all repeating items
UrlCheck bool `json:"UrlCheck,omitempty"` // Check [UrlStr] before loading
UrlLoad bool `json:"UrlLoad,omitempty"` // Control if [UrlStr] should be load at the beginning of [Run]
UrlStr string `json:"UrlStr,omitempty"` // URL string used in [LoadPage]. Not use if [UrlLoad] = false
ScrollMax int `json:"ScrollMax,omitempty"` // Maximum time the page should be scrolled
IInfoList *IInfoList `json:"IInfoList,omitempty"` // Pointer of array of IInfo. If not nil, IInfo item will be added to the array
}
type State ¶
type State struct {
*basestruct.Base
Elements *rod.Elements `json:"Elements"` // Result of [Processor.V020_Elements()]
ElementLast *rod.Element `json:"ElementLast"` // Last element of the previous scroll loop iteration
ElementLastScroll *rod.Element `json:"ElementLastScroll"` // Element used for previous scroll (not necessary last loop iteration)
ElementCountLast int `json:"ElementCountLast"` // Number of elements of previous loop iteration
InfoLast IInfo `json:"InfoLast"` // [Info] of [ElementLast]. Return from [Processor.V030_ElementInfo()]
Scroll bool `json:"Scroll"` // Used by [breakLoop]. True = to scroll. False = don't scroll.
ScrollCount int `json:"ScrollCount"` // Total number of times [Processor.ElementScroll()] called
}
[State] ¶
Used at the beginning of [Processor.Run()] scroll loop for [breakLoop] calculation, and [Processor.ElementScroll()] for scrolling.
At the bottom of 'Run()' scroll loop, it is passed into [Processor.V100_ScrollLoopEnd()] for customized scroll calculation.
Directories
¶
| Path | Synopsis |
|---|---|
|
example
|
|
|
x-feed
command
|
|
|
x-feed/xfp
xfp - X.com Feed Processor README (1)
|
xfp - X.com Feed Processor README (1) |
Click to show internal directories.
Click to hide internal directories.