how to render page phantom js every minute
how to render page phantom js every minute
I want to render a website page with phantom js, argar can render automatically every few minutes?
Here is my code:
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);
);
1 Answer
1
Hope this will help:->
The setInterval() method calls a function or evaluates an expression at specified intervals (in milliseconds).
The setInterval() method will continue calling the function until clearInterval() is called, or the window is closed.
The ID value returned by setInterval() is used as the parameter for the clearInterval() method.
1000 ms = 1 second.
Tip: To execute a function only once, after a specified number of milliseconds, use the setTimeout() method.
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 takes 2 arguments
1.)Function
2.)interval to again render the page(in milliseconds)
this code is not work, I run in cmd
– exsan renaldhi
Sep 10 '18 at 3:27
@exsanrenaldhi now check the above example.
– Shivam Arora
Sep 10 '18 at 3:53
thanks for answer, i will try this
– exsan renaldhi
Sep 15 '18 at 3:05
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Welcome to S.O. Including a brief description of how the code answers the question will help others with the same problem.
– Ageax
Sep 10 '18 at 3:25