参考自:https://blog.csdn.net/xc_zhou/article/details/80755236
from selenium import webdriver
from PIL import Image
import time
driver = webdriver.PhantomJS(executable_path=r"D:\软件安装\phantomjs-2.1.1-windows\bin\phantomjs.exe")
# 全屏显示
driver.maximize_window()
driver.get("your url")
time.sleep(5)
# 滑动滚动条,使js加载的图片能显示出来
driver.execute_script("""
(function () {
var y = 0;
var step = 100;
window.scroll(0, 0);
function f() {
if (y < document.body.scrollHeight) {
y += step;
window.scroll(0, y);
setTimeout(f, 100);
} else {
window.scroll(0, 0);
document.title += "scroll-done";
}
}
setTimeout(f, 1000);
})();
""")
time.sleep(5)
driver.save_screenshot('capture.png') #截取全屏
driver.quit()
补充:time.sleep需要自调[不同的网页,加载速度不一样]