import argparse
from selenium import webdriver
from selenium.webdriver.common.by import By
# define the command line arguments using argparse
parser = argparse.ArgumentParser(description='Take a screenshot of a web page or a specific element on the page.')
parser.add_argument('url', help='the URL of the web page to take a screenshot of')
parser.add_argument('-e', '--element', help='the CSS selector of the element to take a screenshot of')
parser.add_argument('-o', '--output', default='screenshot.png', help='the name of the output file (default: screenshot.png)')
# parse the command line arguments
args = parser.parse_args()
# create a new Chrome web driver instance
driver = webdriver.Chrome()
# navigate to the web page
driver.get(args.url)
if args.element:
# find the element to take a screenshot of
element = driver.find_element(By.CSS_SELECTOR,args.element)
# take a screenshot of the element
element.screenshot(args.output)
else:
# take a screenshot of the entire page
driver.save_screenshot(args.output)
# close the browser
driver.quit()
# python screenshot.py http://example.com -o screenshot.png