after setting the band size of the browser (800600), using the screenshot method, the picture obtained is actually larger than the browser itself.
ask me, what went wrong? How to deal with
from io import BytesIO
from PIL import Image
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
browser = webdriver.Chrome()
browser.set_window_size(800, 600)
wait = WebDriverWait(browser, 20)
browser.get("https://www.baidu.com/")
screenshot = browser.get_screenshot_as_png()
screenshot = Image.open(BytesIO(screenshot))
browser.get_screenshot_as_file("test.png")
print("size:", browser.get_window_size())
print("size:", screenshot.size)
browser.close()
browser size: {"width": 800," height": 600}
full picture size: (1179699)
update:
has been tested, and the screenshot of the whole image is correct only when using its headless mode.
=
Chrome 67.0.3396.99
selenium 3.13
python 3.6 win10 3.7
win10
the screenshot is always too large