GitHub地址node
const Nightmare= require('nightmare');
const nightmare = Nightmare({ show: true });
nightmare //打開網址 .goto("http://www.zhaopin.com/") //輸入 .type("[name='loginname']","*******") .type("[name='Password']","********") //點擊事件(根據選擇器) .click(".logbtn button") //等待 .wait(2000) .goto("https://i.zhaopin.com/") .wait(2000) .click("a.myLinkA.linkRefresh") .end() .wait(2000) .catch((error) => { console.error('Search failed:', error); });
$ npm install -g cron
var cronJob = require("cron").CronJob; //每秒鐘執行一次 new cronJob('* * * * * *', function () { //your job code here }, null, true, 'Asia/Chongqing'); //每隔30秒執行一次,會在0秒和30秒處執行 new cronJob('*/30 * * * * *', function () { //your job code here }, null, true, 'Asia/Chongqing'); //從早上8點到下午18點,每隔半個小時執行一次,會在0分和30分處執行 new cronJob('* */30 8-18 * * *', function () { //your job code here }, null, true, 'Asia/Chongqing'); //在天天的10點和18點的第26分鐘各執行一次 new cronJob('* 26 10,18 * * *', function () { //your job code here }, null, true, 'Asia/Chongqing');
var cronJob = require("cron").CronJob;
var jobid = new cronJob('* 26 10,18 * * *', function () { //your job code here }, null, false, 'Asia/Chongqing'); jobid.start();
cronJob中的時間適合時區有關的,因此須要配合正確的時區,關於時間能夠參考這篇文章: centos中查看系統時區和相關設置
var jobid = new cronJob('* * * * * *', function () { //your job code here }, null, false, 'Asia/Chongqing'); var second = "12"; var minute = "0"; var hour = "8-19"; var interval = "3"; var time = require("cron").time(second + ' ' + minute + ' ' + hour+ '/' + interval + ' * * *', 'Asia/Chongqing'); jobid.stop(); jobid.setTime(time); jobid.start();
var jobid = new cronJob('* 26 10,18 * * *', function () { //your job code here }, null, true, 'Asia/Chongqing'); ... jobid.stop();
var cronJob = require("cron").CronJob; //引入個人須要做業的程序 var App=require("./app"); new cronJob('* 30 09,18 * * *', function () { console.log("開始執行定時更新任務"); App.appcron(); }, null, true, 'Asia/Chongqing');