import os
import sys
import hashlib
from playwright.sync_api import sync_playwright

webpage_link = sys.argv[1]

m = hashlib.md5()
m.update(webpage_link.encode('UTF-8'))
filename = m.hexdigest()
def take_element_screenshot(webpage_link, filename):
    with sync_playwright() as p:
        # Launch the browser
        browser = p.chromium.launch(headless=True)
        context = browser.new_context()
        page = context.new_page()
        
        # Navigate to the desired URL
        page.goto(webpage_link)
        
        # Select the specific element
       # element = page.locator(".w3-info.intro")  # Replace 'h1' with your desired CSS selector

        # Take a screenshot of the element
        page.screenshot(path="images/"+filename+".png", full_page=True)
       # element.screenshot(path="element_screenshot.png")
        
        # Close the browser
        browser.close()
        print("Screenshot saved as 'element_screenshot2.png'.")


# Run the function
take_element_screenshot(webpage_link, filename)