How To Take Screenshot Of Website Using Python?

 

thumbnail


Welcome Coders, In this tutorial we are going to learn that how we can take screenshot of website, webpages using python.

We are going to use selenium module to perform this task.

About Selenium:

It is a module that is used for controlling web browser through your written programs and perform automation of browsers. It works for all browsers and Operating System.
Read More At: About Selenium

In  This Tutorial We are using chrome as a browser and window as a Operating system for performing this task.

Selenium web drivers are required for selenium to execute this task. Web Drivers are different for different browsers.

About Selenium Web drivers:

It is a automation framework that allow to execute and perform various test over the browsers. These frameworks operates by accepting commands, sending commands to browsers and then executing tasks.

 Selenium Web drivers Download Links:

 Edge: https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

Firefox: https://github.com/mozilla/geckodriver/releases

Safari: https://webkit.org/blog/6900/webdriver-support-in-safari-10/


Installation 

To Install Selenium
pip install selenium

Source Code

from selenium import webdriver

options = webdriver.ChromeOptions()
#Adding Some Important Arguments
options.add_argument("--headless")
options.add_argument("--window-size=1024,768")
options.add_argument("--ignore-cerificate-errors")
options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36")
driver=webdriver.Chrome(r"Your Chrome Driver Path", chrome_options=options)

driver.get("https://www.instagram.com/community_programmer/")

driver.save_screenshot("screenshot.png")
print("Screenshot Saved")

0 Comments