On Page Evaluation Functions
Using custom evaluation functions with Waterfall-Fetch
Evaluation Functions
Evaluation functions in Waterfall-Fetch allow you to execute custom JavaScript code in the context of the fetched web page when using the Puppeteer strategy.
What are Evaluation Functions?
An evaluation function is a user-defined function that takes a page
object as its parameter. This page
object represents the current state of the web page being interacted with, allowing you to execute JavaScript within the context of that page.
Syntax
Usage
You can pass an evaluation function as part of the options object when calling getHtml
:
Use Cases
Evaluation functions are particularly useful for:
- Extracting specific data from the page
- Interacting with the page (e.g., clicking buttons, filling forms)
- Waiting for dynamic content to load
- Bypassing client-side rendering issues
Example: Infinite Scroll
Here’s an example of using an evaluation function to handle infinite scroll:
By leveraging evaluation functions, you can extend Waterfall-Fetch’s capabilities to handle complex scraping scenarios and extract precisely the data you need.