如何每分钟渲染页面幻像js

问题描述 投票:1回答:1

我想用幻影js渲染一个网页,argar可以每隔几分钟自动渲染一次?

这是我的代码:

var url = 'http://live.7msport.com';
var page = require ('webpage'). create ();
var fs = require ('fs');

page.open (url, function (status) {
    if (status! == 'success') {
        console.log ('Fail');
        phantom.exit ();
    } else {
        window.setTimeout (function () {
       fs.write ('index.php', page.content, 'w');
       phantom.exit ();
        }, 2000);
    }
});
javascript phantomjs
1个回答
0
投票

希望这会有所帮助: - >

setInterval()方法以指定的时间间隔(以毫秒为单位)调用函数或计算表达式。

setInterval()方法将继续调用该函数,直到调用clearInterval()或关闭窗口。

setInterval()返回的ID值用作clearInterval()方法的参数。

1000毫秒= 1秒。

提示:要在指定的毫秒数后执行一次函数,请使用setTimeout()方法。

function myFunction() {
    setInterval(function(){ alert("Hello"); }, 3000);
}
<!DOCTYPE html>
<html>
<body>

<p>Click the button to wait 3 seconds, then alert "Hello".</p>
<p>After clicking away the alert box, an new alert box will appear in 3 seconds. This goes on forever...</p>
<button onclick="myFunction()">Try it</button>
</body>
</html>

var url = 'http://live.7msport.com'; 
var page = require ('webpage'). create (); 
var fs = require ('fs'); 
page.open (url, function (status) { if (status! == 'success') { console.log ('Fail'); phantom.exit (); } 
else 
{ window.setInterval (function () {
fs.write ('index.php', page.content, 'w');
phantom.exit (); 
}, 60000); }

});

setInterval接受2个参数1.)函数2.)interval再次呈现页面(以毫秒为单位)

© www.soinside.com 2019 - 2024. All rights reserved.