This function handles pages with infinite scroll when a button must be clicked to load more elements. For a quick start, check out
this video tutorial on how to quickly import and use this premade from within Helium Scraper.
This function takes the following arguments:
- itemSelector: A selector that selects the items in the scrollable area, typically each of the results items. After scrolling down, the previous elements will be deleted to minimize memory consumption. Usually these elements can be automatically selected using the Detect List button on the page.
- buttonSelector: A selector that selects the button that loads more elements.
- scrollDelay: A wait time in milliseconds, to wait for new data to load after scrolling down.
- removeOldElements: Whether to remove old elements after they've been extracted. Should be true unless removing elements breaks the page's scrolling mechanism.
When the action runs, it selects each of the list items on the browser, so if extracting from a list, the list items should
not be selected again above the extract action or below this action.
To use this on your project, follow
these instructions:
{
"api": "1.0.2.1",
"name": "InfiniteScrollButton",
"options": {
"take": true
},
"parameters": {
"itemSelector": {
"caption": "List Item Selector",
"type": "selector"
},
"buttonSelector": {
"caption": "Load More Button Selector",
"type": "selector"
},
"scrollDelay": {
"caption": "After Scroll Delay",
"type": "number",
"default": 100
},
"removeOldElements": {
"caption": "Remove Old Elements",
"type": "boolean",
"default": true
}
}
}
Code: Select all
function (itemSelector buttonSelector scrollDelay removeOldElements)
Browser.ScrollLoop
· itemSelector
· buttonSelector
Browser.Click
Browser.Wait
· scrollDelay
· removeOldElements
The maximum number of elements to be extracted can be limited using the
Sequence.Take function as in the following example (this example assumes the project already contains a selector called
ListItem that selects the list items, another selector called
LoadMoreButton that selects the button that loads more elements, and the code above was pasted under a global called
InfiniteScrollButton):
Code: Select all
Sequence.Take
· 500
· InfiniteScrollButton
· Select.ListItem
· Select.LoadMoreButton
· 100
· true
Note that the example above would extract 500 list items, each of which will usually occur many times per page, as opposed to 500 pages.