Screenshot utilities
conatus.utils.browser.post_processing.screenshot
¶
📸 Utilities to take screenshots of a webpage.
Heavily uses the Pillow library.
get_img_screenshot_async
async
¶
Take a screenshot of the page from a Playwright page object.
Note: The expected type for a Playwright page is
playwright.async_api.Page.
| PARAMETER | DESCRIPTION |
|---|---|
pw_page
|
Playwright page object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Image
|
Image.Image: Screenshot of the page. |
Source code in conatus/utils/browser/post_processing/screenshot.py
get_img_screenshot
¶
Take a screenshot of the page from a Playwright page object.
| PARAMETER | DESCRIPTION |
|---|---|
pw_page
|
Playwright page object.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Image
|
Image.Image: Screenshot of the page. |
Source code in conatus/utils/browser/post_processing/screenshot.py
get_base64_screenshot
¶
Convert the screenshot to base64.
Note the use of img_res to resize the image. The equation is img_res x
img_res * H / W. This means, for instance, that if the image is 1920 x
1080, and img_res is 500, the image will be resized to 500 x 281.
| PARAMETER | DESCRIPTION |
|---|---|
img
|
Screenshot of the page.
TYPE:
|
img_res
|
Resolution of the image. The image will be resized to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
str
|
Base64 encoded screenshot of the page.
TYPE:
|
Source code in conatus/utils/browser/post_processing/screenshot.py
get_screenshots_async
async
¶
get_screenshots_async(
page: Page | Page,
img_res: int = DEFAULT_SCREENSHOT_RESOLUTION,
) -> tuple[Image, str]
Get two screenshots (Img + b64) of the (Conatus or Playwright) page.
Note: The expected type for a Playwright page is
playwright.async_api._generated.Page.
| PARAMETER | DESCRIPTION |
|---|---|
page
|
Page object (either Playwright or Conatus)
TYPE:
|
img_res
|
Resolution of the image. The image will be resized to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Image, str]
|
tuple[Image.Image, str]: The screenshot and base64 encoded screenshot. |
Source code in conatus/utils/browser/post_processing/screenshot.py
get_screenshots
¶
get_screenshots(
page: Page | Page,
img_res: int = DEFAULT_SCREENSHOT_RESOLUTION,
) -> tuple[Image, str]
Get two screenshots (Img + b64) of the (Conatus or Playwright) page.
| PARAMETER | DESCRIPTION |
|---|---|
page
|
Page object (either Playwright or Conatus)
TYPE:
|
img_res
|
Resolution of the image. The image will be resized to
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[Image, str]
|
tuple[Image.Image, str]: The screenshot and base64 encoded screenshot. |