Screenshot of a particular quality with Python and Playwright
Install Playwright and Playwright client for Python
pip install pytest-playwright
playwright install
Convert HTML to JPG and save to file
import asyncio
from playwright.async_api import async_playwright
async def main():
async with async_playwright() as p:
browser = await p.chromium.launch()
page = await browser.new_page()
await page.set_viewport_size({'width': 480, 'height': 240})
await page.goto('https://www.bbc.co.uk/news/business-63709754')
await page.screenshot(path='quality.png', type='jpeg', quality=75)
await browser.close()
asyncio.run(main())
Find out how to change the size of the viewport with Python and Playwright.
We created Urlbox to make converting HTML to images easy
Learn more about our website screenshot API.