Core Concepts

Getting Multiple Results: WithAllThatMatch & Pagination

WithAllThatMatch controls how many elements GetGrid collects. On a single page, across multiple pages via WithNextPageButton, or via WithInfiniteScroll. The same number means different things depending on how many results the first page returns.

One Page: WithAllThatMatch by Itself

WithAllThatMatch defaults to 1. GetGrid returns a single matched element per selector. WithAllThatMatch(-1) returns every matching element on the current page. WithAllThatMatch(N) for N greater than 1 returns up to N matches from the current page only. GPAL does not page or scroll unless WithNextPageButton or WithInfiniteScroll is also specified.

Pagination: Per-Page Cap vs Total Cap

Add WithNextPageButton or WithInfiniteScroll and WithAllThatMatch takes on a second meaning. If N is less than or equal to the results found on the first page, N caps each page. GPAL keeps turning pages until none remain. If N is greater than the first page's results, or N is -1, N becomes a total cap across all pages combined, and GPAL stops once that many rows have been collected.

// Per-page cap: top 3 results from each page,

// keep paging until no Next button is found

GPAL.WithSelector("li.result")

.WithAllThatMatch(3)

.WithNextPageButton(nextBtn)

.GetGrid();

// Total cap: up to 50 results across as many pages

// as needed (50 > results on page 1)

GPAL.WithSelector("li.result")

.WithAllThatMatch(50)

.WithNextPageButton(nextBtn)

.GetGrid();

// Unlimited: page until no Next button remains

GPAL.WithSelector("li.result")

.WithAllThatMatch(-1)

.WithNextPageButton(nextBtn)

.GetGrid();

TIP

GPAL compares WithAllThatMatch against the result count from the first page only, and that decision. Per-page cap or total cap. Holds for the rest of the run.

Infinite Scroll and Duplicate Rows

WithInfiniteScroll has no Next button to click. GPAL scrolls to the bottom of the page and re-queries the same selectors. Pages that append new content below the old usually leave previously-seen elements in the DOM, so a naive re-query would return them again. GPAL deduplicates the collected rows so each matched element is only added to the result grid once, no matter how many scrolls it survives.

WARNING

Sites that recycle DOM nodes as you scroll (virtualized feeds like Facebook or X) may reuse the same element for different content, or remove old rows entirely. Deduplication handles the common append-only case, but cannot guarantee complete, duplicate-free results on a virtualized feed.