Compatibility: Only available on Node.js.
This notebook provides a quick overview for getting started with PuppeteerWebBaseLoader. For detailed documentation of all PuppeteerWebBaseLoader features and configurations head to the API reference.
Puppeteer is a Node.js library that provides a high-level API for controlling headless Chrome or Chromium. You can use Puppeteer to automate web page interactions, including extracting data from dynamic web pages that require JavaScript to render.
If you want a lighterweight solution, and the webpages you want to load do not require JavaScript to render, you can use the CheerioWebBaseLoader instead.
Overview
Integration details
Loader features
Setup
To access PuppeteerWebBaseLoader document loader you’ll need to install the @langchain/community integration package, along with the puppeteer peer dependency.
Credentials
If you want to get automated tracing of your model calls you can also set your LangSmith API key by uncommenting below:
Installation
The LangChain PuppeteerWebBaseLoader integration lives in the @langchain/community package:
Instantiation
Now we can instantiate our model object and load documents:
Load
Options
Here’s an explanation of the parameters you can pass to the PuppeteerWebBaseLoader constructor using the PuppeteerWebBaseLoaderOptions interface:
-
launchOptions: an optional object that specifies additional options to pass to the puppeteer.launch() method. This can include options such as the headless flag to launch the browser in headless mode, or the slowMo option to slow down Puppeteer’s actions to make them easier to follow.
-
gotoOptions: an optional object that specifies additional options to pass to the page.goto() method. This can include options such as the timeout option to specify the maximum navigation time in milliseconds, or the waitUntil option to specify when to consider the navigation as successful.
-
evaluate: an optional function that can be used to evaluate JavaScript code on the page using the page.evaluate() method. This can be useful for extracting data from the page or interacting with page elements. The function should return a Promise that resolves to a string containing the result of the evaluation.
By passing these options to the PuppeteerWebBaseLoader constructor, you can customize the behavior of the loader and use Puppeteer’s powerful features to scrape and interact with web pages.
Screenshots
To take a screenshot of a site, initialize the loader the same as above, and call the .screenshot() method.
This will return an instance of Document where the page content is a base64 encoded image, and the metadata contains a source field with the URL of the page.
API reference
For detailed documentation of all PuppeteerWebBaseLoader features and configurations head to the API reference.