【发布时间】:2018-06-13 20:09:17
【问题描述】:
我正在寻找一个页面作为学习 phantomjs 的练习,但是我目前遇到了一个问题。图像加载被推迟,所以我试图弄清楚如何让 phantom js 向下滚动并等待图像加载。滚动到页面底部不起作用,所以我想每 3 秒滚动 100 像素,直到它到达页面底部。我将如何实现这一目标?
const phantom = require('phantom');
(async function() {
const instance = await phantom.create();
const page = await instance.createPage();
await page.on('onResourceRequested', function(requestData) {
console.info('Requesting', requestData.url);
});
await page.open(<URL>);
const js = await page.includeJs('http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js');
const data = await page.evaluate(function() {
// Do something
});
page.render('test.pdf');
await page.close();
await instance.exit();
})();
【问题讨论】:
-
我认为这是不可能的,因为 phantomjs 没有滚动。渲染通常是整个页面。因此,要么是页面上的错误,要么您必须以某种方式为每个图像手动触发加载。
标签: javascript jquery node.js phantomjs phantomjs-node