鍍金池/ 問答/Python  HTML/ python+selenium get_screenshot_as_png方法獲

python+selenium get_screenshot_as_png方法獲得的圖片大小比預(yù)計(jì)的要大

在設(shè)定瀏覽器的帶大小后(800,600),使用截圖方法,獲得的圖片居然比瀏覽器本身還大。
請(qǐng)教下,到底是哪里出了問題?該如何處理

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()

瀏覽器size: {'width': 800, 'height': 600}
全圖size: (1179, 699)

更新:
測(cè)試了下,僅在使用其headless模式下,對(duì)全圖的截圖才為正確。

===========================================================
Chrome 67.0.3396.99
selenium 3.13
python 3.6/3.7
win10
上述環(huán)境下始終截圖過大

回答
編輯回答
擱淺

可能是你的軟件版本問題,我用最新版的 selenium, python 3,及 chrome,輸出結(jié)果符合預(yù)期,如下

瀏覽器size: {'width': 800, 'height': 600}
全圖size: (800, 491)
2018年3月5日 14:05