gpt4 book ai didi

javascript - PhantomJS 中的滚动页面

转载 作者:行者123 更新时间:2023-12-04 23:24:45 25 4
gpt4 key购买 nike

我使用 PhantomJS 和 ffmpeg 从帧中渲染视频。我尝试做滚动框架并渲染它,但没有成功。
我的代码是:

  const page = require("webpage").create();

const getImage = (link, duration) => {
page.viewportSize = { width: windowWidth, height: windowHeight };
page.scrollPosition = {top: 0, left: 0};
let videoDuration = Math.floor(duration * 25);

if (link.startsWith("http://") || link.startsWith("https://")) {
page.open(link, () => {
let frame = 0;
setInterval(() => {
page.render("frames/image" + frame++ + ".png", { format: "png"
});
page.evaluate(function () { window.scrollBy = 100; });
if (frame > videoDuration) {
phantom.exit();
}
}, 25);
});
} else {
console.log("Enter a valid link");
phantom.exit();
}
};

getImage(imageLink, duration);

当我运行渲染的视频时,它只作为任何视频播放并且没有任何滚动。
我做错了什么?
PS:我发现 page.scoolPosition 的解决方案很少 - 但它们也不起作用。

最佳答案

尝试打开具有不同超时的页面后等待。

const page = require("webpage").create();

const getImage = (link, duration) => {
page.viewportSize = { width: windowWidth, height: windowHeight };
page.scrollPosition = { top: 0, left: 0 };
let videoDuration = Math.floor(duration * 25);

if (link.startsWith("http://") || link.startsWith("https://")) {
page.open(link, () => {
let frame = 0;

setTimeout(() => {
setInterval(() => {
page.render("frames/image" + frame++ + ".png", {
format: "png"
});
page.evaluate(function () { window.scrollBy(0, 100); });
if (frame > videoDuration) {
phantom.exit();
}
}, 25);
}, 1000);
});
} else {
console.log("Enter a valid link");
phantom.exit();
}
};

getImage(imageLink, duration);

尝试使用其他滚动方式: window.scrollTo(...) , document.body.scrollTop = ...
更新:
window.scrollBy(X, Y);是函数,不是属性。

关于javascript - PhantomJS 中的滚动页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52559243/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com