from selenium import webdriver
from PIL import Image
# Set up Selenium webdriver (make sure you have the corresponding browser driver installed)
driver = webdriver.Firefox()
# Navigate to the desired web page
driver.get('https://example.com')
# Retrieve the webpage dimensions
total_width = driver.execute_script('return document.documentElement.scrollWidth')
total_height = driver.execute_script('return document.documentElement.scrollHeight')
# Set the window size of the browser according to the webpage dimensions
driver.set_window_size(total_width, total_height)
# Take a screenshot of the entire page
screenshot = driver.get_screenshot_as_png()
# Save the screenshot to a file
with open('screenshot.png', 'wb') as file:
file.write(screenshot)
# Close the browser
driver.quit()