Screenshot
screenshot: object;
What's This?
The screenshot option provides settings to capture screenshots of the web pages being scraped, allowing users to visually see the content of the page at the time of scraping.
Properties
-
use: A boolean setting that when set to true, captures a screenshot of the page. Default is false.
-
options: Configuration settings for the screenshot capture. These include:
-
captureBeyondViewport: If true, captures content beyond the visible area or viewport.
-
Default is true.
-
encoding: Specifies the encoding of the image. Options are 'binary' or 'base64'.
-
Default is ScreenshotEncoding.BINARY.
-
fromSurface: If true, captures from the surface rather than the view. Default is true.
-
fullPage: Captures the entire webpage if set to true. Default is false.
-
omitBackground: Removes the default white background for transparent screenshot capture when set to true. Default is true.
-
type: Specifies the image format. Options are 'jpeg', 'png', or 'webp'. Default is ScreenshotType.JPEG.
-
selector: (Optional) take a screenshot of a specific element. If a selector is set, clip must be null otherwise it overrides it.
-
quality: (Optional) Defines the image quality with a number. Not applicable for ScreenshotType.PNG. Default is null.
-
clip:(Optional) An object that defines a specific region of the page to capture.
-
x:number for Horizontal position for the center of the clipping region .
-
y:number for Vertical position for the center of the clipping region.
-
width:number for Width of the clipping region.
-
height:number for Height of the clipping region.
-
scale:(Optional) Scale for the clipping region.Default is 1.
-
-
How Does it Work?
- Example: Setting screenshot= {use: true, options: {fullPage: true, type: 'png'}} would capture a full-page screenshot in PNG format.
When Should I Use This?
Activate the screenshot option when you want a visual record of the web page. It's particularly handy for visually verifying content, troubleshooting layout issues, or keeping a visual archive of web pages at specific points in time.
Methods
setUseScreenshot(boolean)
Configuration Name: screenshot.use
If set to true, returns a screenshot of the page.
Initializing Scraper
const GeonodeScraperApi = require('geonode-scraper-api');
const scraper = new GeonodeScraperApi('<Your_username>', '<Your_password>');
Using Method
scraper.setUseScreenshot(true);
scraper.scrape('https://example.com/');
Using Configuration Object
const config = { screenshot: { use: true } };
scraper.scrape('https://example.com/', config);
screenshotSelector(url: string, selector: string, screenshotOptions?: IScreenshotOptions)
setScreenshotClip(clip: IScreenshotClip)
Configuration Name: screenshot.options.clip
Defines a custom clipping region for the screenshot. Specify (x, y) coordinates, width, and height to capture precise webpage portions. Use an optional scaling factor for finer image control.
Initializing Scraper
const GeonodeScraperApi = require('geonode-scraper-api');
const scraper = new GeonodeScraperApi('<Your_username>', '<Your_password>');
Using Method
const screenshotClip = { x: 150, y: 150, width: 200, width: 200, scale: 1 };
scraper.setScreenshotClip(screenshotClip);
scraper.scrape('https://example.com/');
Using Configuration Object
const screenshotClip = { x: 150, y: 150, width: 200, width: 200, scale: 1 };
const config = { screenshot: { options: { clip: screenshotClip } } };
scraper.scrape('https://example.com/', config);