Infinite Scroll with a "Load More" Button
Posted: Fri Jan 04, 2019 8:11 am
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:
To use this on your project, follow these instructions:
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):
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.
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.
To use this on your project, follow these instructions:
Code: Select all
function (itemSelector buttonSelector scrollDelay removeOldElements)
Browser.ScrollLoop
· itemSelector
· buttonSelector
Browser.Click
Browser.Wait
· scrollDelay
· removeOldElements
Code: Select all
Sequence.Take
· 500
· InfiniteScrollButton
· Select.ListItem
· Select.LoadMoreButton
· 100
· true