Javascript Phantomjs每5秒重新加载一个页面
我希望我的phantomjs脚本继续在给定的参数输入域上执行重新加载/刷新https://google.com 每5秒。我如何做到这一点 phantomjstest.js test.js 您可以使用调用在页面加载后一定时间内加载页面的函数:Javascript Phantomjs每5秒重新加载一个页面,javascript,jquery,phantomjs,mocha-phantomjs,Javascript,Jquery,Phantomjs,Mocha Phantomjs,我希望我的phantomjs脚本继续在给定的参数输入域上执行重新加载/刷新https://google.com 每5秒。我如何做到这一点 phantomjstest.js test.js 您可以使用调用在页面加载后一定时间内加载页面的函数: var page = require('webpage').create(), system = require('system'), address; page.onAlert = function (msg) { console
var page = require('webpage').create(),
system = require('system'),
address;
page.onAlert = function (msg) {
console.log("Received an alert: " + msg);
};
page.onConfirm = function (msg) {
console.log("Received a confirm dialog: " + msg);
return true;
};
function loadPage() {
if (system.args.length === 1) {
console.log("Must provide the address of the webpage");
} else {
address = system.args[1];
page.open(address, function (status) {
if (status === "success") {
console.log("opened web page successfully!");
page.evaluate(function () {
var e = document.createEvent('Events');
e.initEvent('click', true, false);
document.getElementById("link").dispatchEvent(e);
});
}
setTimeout(loadPage, 5000) // Call the function loadPage again in 5 seconds
});
}
}
loadPage()
var page = require('webpage').create(),
system = require('system'),
address;
page.onAlert = function (msg) {
console.log("Received an alert: " + msg);
};
page.onConfirm = function (msg) {
console.log("Received a confirm dialog: " + msg);
return true;
};
function loadPage() {
if (system.args.length === 1) {
console.log("Must provide the address of the webpage");
} else {
address = system.args[1];
page.open(address, function (status) {
if (status === "success") {
console.log("opened web page successfully!");
page.evaluate(function () {
var e = document.createEvent('Events');
e.initEvent('click', true, false);
document.getElementById("link").dispatchEvent(e);
});
}
setTimeout(loadPage, 5000) // Call the function loadPage again in 5 seconds
});
}
}
loadPage()