php截图整个网页,selenium save_screenshot 如何进行全网页截图?

董元徽
2023-12-01

解决的思路通过set_window_size()就是把浏览器的长宽高调大:width = self.session.execute_script(

"document.body.scrollWidth, document.body.offsetWidth, document.documentElement.clientWidth, document.documentElement.scrollWidth, document.documentElement.offsetWidth);")

height = self.session.execute_script(

"return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);")

webdriver.set_window_size(width, height)

webdriver.save_screenshot(path)

如果只是希望调高度,可以改成把宽度固定,比如1028:document.documentElement.offsetWidth);")

height = self.session.execute_script(

"return Math.max(document.body.scrollHeight, document.body.offsetHeight, document.documentElement.clientHeight, document.documentElement.scrollHeight, document.documentElement.offsetHeight);")

webdriver.set_window_size(1028, height)

webdriver.save_screenshot(path)

 类似资料: