Skip to content

[Question]: Download currnet image with python playwright #1189

@agent666

Description

@agent666

Your question

Is it possible to make something like this with Playwright:

import base64
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://somesite.com')
img_base64 = browser.execute_script("""
    var ele = arguments[0];
    var cnv = document.createElement('canvas');
    cnv.width = ele.width; cnv.height = ele.height;
    cnv.getContext('2d').drawImage(ele, 0, 0);
    return cnv.toDataURL('image/jpeg').substring(22);    
    """, browser.find_element_by_xpath("//your_xpath"))
with open(r"image.jpg", 'wb') as f:
    f.write(base64.b64decode(img_base64))

I prefer playwright over selenium but can't find a way with Playwright.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions