selenium长截图,截图整个页面
"""
翻页截图整个页面
"""
# 获取页面的宽度和高度
page_width = web_driver.execute_script("return document.body.scrollWidth")
page_height = web_driver.execute_script("return document.body.scrollHeight")
# 开启设备模拟
web_driver.execute_cdp_cmd('Emulation.setDeviceMetricsOverride',
{'mobile': False, 'width': page_width, 'height': page_height,
'deviceScaleFactor': 1})
# 截图
res = web_driver.execute_cdp_cmd('Page.captureScreenshot', {'fromSurface': True})
img_base64 = res['data']
# 恢复页面到原始状态
web_driver.execute_cdp_cmd('Emulation.clearDeviceMetricsOverride', {})