This short guide explains how to take screenshot of website using Python. It provides instructions for setting up the development environment, a list of steps to write the application, and sample code to capture entire web page screenshot using Python. At the end of the guide, you will get different options to customize your output PNG as per your requirements.
Steps to Capture Full Webpage Screenshot using Python
- Set up the environment using Aspose.HTML for Python via .NET to capture a webpage
- Import the necessary modules to work with the HTML documents and pages
- Apply a license to avoid a watermark in the output image
- Define the URL of the webpage for taking a snapshot
- Load the source URL into the HTMLDocument class object
- Create an instance of the ImageSaveOptions class with image type PNG
- Set the resolution of the output image
- Render the webpage to the PNG image using the convert_html() method
These steps summarize how to take a screenshot of full webpage in Python. Import the necessary modules for working with HTML documents, load a license to avoid watermarks, and load the webpage into an HTMLDocument class object using the URL. Create an object of the ImageSaveOptions class, set all the desired parameters, and render the page using the convert_html() method.
Code to Capture Entire Page Screenshot using Python
This code demonstrates the process to take a screenshot of entire webpage using Python. If you want to make the page screen-friendly instead of printer-friendly, set the options.css.media_type to Screen. Other customizations are possible, such as setting the background color, controlling page layout to fit contents, and making the small text clearer by enabling the options.text.use_hinting.
This guide explains the process to take an image of a webpage. To convert an HTML page to text, refer to the article Convert HTML to Text in Python.