Screenshot of a particular element with Python and Puppeteer

Install Python Puppeteer Implementation and Chromium

pip install pyppeteer

Take a screenshot of the element and save to file

import asyncio
from pyppeteer import launch

async def main():
    browser = await launch()
    page = await browser.newPage()

    await page.goto('')
    element = await page.querySelector('.ssrcss-hmf8ql-BoldText') 
    bounding_box = await element.boundingBox()
    await page.screenshot({'path': 'element.png', 'clip': {'x': bounding_box['x'], 'y': bounding_box['y'], 'width': bounding_box['width'], 'height': bounding_box['height']}})

    await browser.close()

Find out how to take a full-page screenshot with Python and Puppeteer.

We created Urlbox to make converting HTML to images easy

Learn more about our website screenshot API.