Snippets: Python: Puppeteer: Download Image by Screenshot

 20th August 2020 at 2:19pm
import asyncio

from pyppeteer import launch

async def main():
    browser = await launch({'headless': True, 'args': ['--no-sandbox']})
    page = await browser.newPage()
    await page.setViewport({"width": 1280, "height": 926})
    await page.goto('')
    await page.waitForSelector('#svg')

    # Select the #svg img element and save the screenshot.
    svg_image = await page.querySelector('#svg')
    await svg_image.screenshot({
        'path': 'logo-screenshot.png',
        'omitBackground': True,

    await browser.close()

if __name__ == '__main__':