Social Widget

Responsive Ads Here

Friday, December 13, 2019

Take screenshots of web pages using python


Sometimes we want to take a screenshot of a webpage directly using our code without visiting the page.  Thanks to "pyppeteer". With the help of this python library we can take full page screenshots and normal screenshots.

Installation

You can install pypuppeteer from pypi using pip.

Pyppeteer requires python 3.6+. (experimentally supports python 3.5)

Note: When you run pyppeteer first time, it downloads a recent version of Chromium (~100MB). If you don’t prefer this behavior, run pyppeteer-install command before running scripts that uses pyppeteer.

python3 -m pip install pyppeteer

Take a screenshot

The following code takes a screenshot of a webpage and saves it.



codesimple.info
screenshot

Take full page screenshot

The following snippet takes a full-page screenshot by scrolling down automatically till the end of the page.



just add one more attribute 'fullPage': True to the screenshot function.

codesimple.info
full page screenshot

More custom functions can be found here.

#python #screenshot #pyppeteer

No comments:

Post a Comment