Capture Screenshots
screenshotURL(url: string, screenshotOptions?: IScreenshotOptions, savePath?: string)
Parameters
- Name
url
- Type
- string
- Description
The URL of the webpage you want to scrape.
- Name
screenshotOptions
- Type
- IScreenshotOptions, optional
- Description
An object containing specific options for the screenshot capture.
- Name
savePath
- Type
- string, optional
- Description
The path where you want to save the captured screenshot. By default, it's saved in the main folder with a default name.
Description
Capture visual content of web pages. This method uses the .scrape() with screenshot capture enabled. The image data is converted into a file and saved in the main folder by default.
Usage
- Basic: Provide the URL of the webpage you want to capture. The screenshot will be saved using default settings.
scraper
.screenshotURL(`https://www.example.com/`)
.then((res) => {
console.log('saved at:', res);
})
.catch((error) => {
console.log('Error:', error.message);
});
Example Response
saved at: ./Screenshot-1692096987839.png
Using Custom Configuration
Customize the screenshot capture by providing specific options.
const options: IScreenshotOptions = {
captureBeyondViewport: false,
encoding: ScreenshotEncoding.BINARY,
fromSurface: false,
fullPage: false,
omitBackground: true,
type: ScreenshotType.JPEG,
};
scraper
.screenshotURL(`https://www.example.com/`, options, '../screenshot')
.then((res) => {
console.log('saved at:', res);
})
.catch((error) => {
console.log('Error:', error.message);
});
Example Response
saved at: ../screenshot.jpeg