Задать вопрос
  • Как убрать все лишне на google maps?

    @Syamm
    import sys, traceback
    import time
    from selenium import webdriver
    from PIL import Image
    from PIL import ImageGrab
    from selenium.webdriver.common.by import By

    # Removing fields from Google Maps
    removing_fields = [
    "var element = document.getElementById(\"omnibox-container\");element.remove();",
    "var element = document.getElementById(\"watermark\");element.remove();",
    "var element = document.getElementById(\"vasquette\");element.remove();",
    "var element = document.getElementsByClassName(\"app-viewcard-strip\");element[0].remove();",
    "var element = document.getElementsByClassName(\"scene-footer-container\");element[0].remove();",
    ]

    def js_code_execute(driver, js_string: str):
    """Execute the JS code"""
    print( "js_code_execute : ", js_string )
    driver.execute_script(js_string)

    def remove_any_blocks( driver ) :
    """Remove any Fields"""
    for x in removing_fields:
    js_code_execute( driver, x )

    def remove_buttons( driver ) :
    """Remove Buttons"""
    list = driver.find_elements(By.XPATH, '//button')

    for x in list:
    driver.execute_script("""var element = arguments[0]; element.parentNode.removeChild(element);""", x )

    driver = webdriver.Chrome()
    driver.maximize_window()
    url = 'https://www.google.com/maps/@40.0100192,-83.013414...'
    driver.get(url)
    print( " A1 " )

    try:
    time.sleep( 8 )
    print( "title = ", driver.title )
    print( "url = ", driver.current_url )

    remove_any_blocks( driver )
    remove_buttons( driver )

    name = "test10.png"
    # image = ImageGrab.grab()
    # image.save( name )
    driver.save_screenshot( name )
    print( "saveFile ", name )
    # input( "Press Enter" );

    except:
    print( " A4 " )
    Type, Value, Trace = sys.exc_info()
    traceback.print_exception( Type, Value, Trace, limit = 5, file=sys.stdout )

    finally:
    print( "A5 " )
    driver.quit()
    Ответ написан