[Python] Update Chrome, python code to create png does not longer work

Discussão em 'Python' iniciado por Stack, Outubro 1, 2024.

  1. Stack

    Stack Membro Participativo

    I have code which creates a screenshot from internally created html files. Chrome issued an update and since then we can no longer take proper screenshot. Each screenshot has a black border at the bottom and it also doesn't show the entire html.

    Is there a solution without downgrading Chrome.

    with open("{}.html".format(filename), "w+") as file:
    file.write(string)


    chrome_options = Options()
    chrome_options.add_argument("no-sandbox");
    chrome_options.add_argument("headless");
    chrome_options.add_argument("window-size=1920,1080");
    browser = webdriver.Chrome(options=chrome_options)


    print(os.getcwd())

    browser.get(os.path.join('file://{}.html').format(filename).replace("\\", "/"))
    #browser.get(os.path.join('file://' + os.getcwd() + '/{}.html').format(filename).replace("\\", "/"))

    time.sleep(10)

    browser.save_screenshot('{}.png'.format(filename))
    browser.quit()

    im = Image.open('{}.png'.format(filename))

    left = 0
    top = 0
    right = 1080
    bottom = 1080

    im1 = im.crop((left, top, right, bottom))
    im1.save('{}.png'.format(filename))

    Continue reading...

Compartilhe esta Página