app.py
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By import time def save_google_maps_screenshot(address, output_file="map_screenshot.png"): # Set up headless Chrome chrome_options = Options() chrome_options.add_argument("--headless") chrome_options.add_argument("--window-size=1280,720") # Initialize driver (make sure chromedriver is installed) driver = webdriver.Chrome(options=chrome_options) try: # Build the Google Maps URL query = address.replace(' ', '+') url = f"https://www.google.com/maps/place/{query}" # Open the URL driver.get(url) time.sleep(5) # wait for map to load # Remove unwanted overlays (cookies, popups) try: driver.find_element(By.ID, "W0wltc").click() except: pass # Take screenshot driver.save_screenshot(output_file) print(f"Screenshot saved as {output_file}") finally: driver.quit() # --- Usage --- address_input = input("Enter the address: ") save_google_maps_screenshot(address_input) |