我希望我的 phantomjs 脚本每秒对给定的参数输入域执行重新加载/https://google.com
刷新5
。我如何做到这一点?
phantomjs test.js https://google.com
- 测试.js
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;
};
if (system.args.length === 1) {
console.log("Must provide the address of the webpage");
} else {
address = system.args[1];
for(var i=0; i <= 10; i++){
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);
});
}
}); }
}