how to take screenshots with selenium webdriver python

from selenium import webdriver
from time import sleep

driver = webdriver.Firefox()
driver.get('https://www.python.org')
sleep(1)

driver.get_screenshot_as_file("screenshot.png")
driver.quit()
print("end...")

Here is what the above code is Doing:
1. We’re importing the webdriver module from selenium.
2. We’re creating a new instance of the Firefox driver.
3. We’re telling the driver to get the Python home page.
4. We’re telling the driver to wait 1 second before doing anything else.
5. We’re telling the driver to take a screenshot of the page and save it as a PNG file.
6. We’re telling the driver to quit.
7. We’re printing “end…” to the console.