BrowserTab.screenshot_to_image

def screenshot_to_image(
self,
image_file: str,
mode: Literal["bounds", "viewport", "full"] = ScreenShotMode.Full,
rect: Rectangle = None,
wait_for_page_delay: int = 0
) -> None

Save current browser tab’s screenshot to file using CDP tech. Only support for chromium web tabs.

Parameters:
image_file[Required]: str
   File path to save image.
mode: Literal[“bounds”, “viewport”, “full”] = ScreenShotMode.Full
   Define the mode to capture browser tab’s screenshot:
     bounds: takes a screenshot of the specified rectangle of the page, using parameter rect to define the rectangle.
     viewport: takes a screenshot of the currently visible viewport.
     full: takes a screenshot of the full scrollable page, using parameter wait_for_page_delay to wait the page ready.
next_page_button_locator: Union[_Locator, str] = None
   The visit path of locator for goto next page UI element. If it’s None, means just extract the current page data.
rect: Rectangle = None
   an object which specifies clipping of the resulting image.
wait_for_page_delay: int = 0
   The timout for waiting for the page ready, the unit is second.

Returns:
 None

Example:


from clicknium import clicknium as cc
from clicknium.common.enums import ScreenShotMode
import os,sys


file = os.path.join(os.path.abspath(sys.path[0]), "tmp.jpg")
tab = cc.chrome.open("https://clicknium.com")
tab.screenshot_to_image(file, ScreenShotMode.Viewport)

Previousscrape_dataNextactivate

What are your feelings
Updated on 29 August 2023