公司自动打卡与考勤作弊

来源:互联网 发布:淘宝设计师助手官网 编辑:程序博客网 时间:2024/05/30 04:30

最近老是忘记打卡,导致考勤异常,于是想来是时候做一个自动化打卡的服务。

能够实现特定时间内自动打卡,不用手动登陆打卡界面进行打卡。

并且服务的配置能够设定该服务在周一到周日的早上哪个时间段打卡,在晚上的哪个时间段打卡,全部过程无需人工干预都是自动化配置。


初步找了下解决方案,找到了一个叫phantomJS的东西,一种高度模拟浏览器的js语言。具体介绍见:http://phantomjs.org/


目前的进度是,已经能够实现自动登陆和自动打卡,下一步打算吧这个过程做成长期的,并且是可配置的服务(比如设置周一什么时候打卡,周二什么时候打卡等等)。


下面把自动登陆和自动打卡的核心逻辑贴一下:

var page = require('webpage').create();var usr = 'your Username';// bug!!!: phantom 's defect : evaluation is a sandbox is indenpendent , it do not accept js objects or varsvar psd = 'your Password';page.onConsoleMessage = function  (msg) {    console.log('enter in ' + msg);};page.open('****login.html', function(status){    page.evaluate(function(usr,psd) {        document.querySelector('input[name=Name]').value = usr;        document.querySelector('input[name=Password]').value = psd;        document.querySelector('input[name=Logon]').click();    },usr,psd);    page.render('login.png');    window.setTimeout(function(){        page.open('******personnal.html',function(status) {            page.render('logon.png');            page.evaluate(function() {                //document.querySelector('a[name=1|1]').click();                console.log(document.title);            });            window.setTimeout(function() {                page.open('*******daka.com',function(status){//bug!!!: it may need to enter ***daka.com multiple times                     page.render('punch.png');//get the punch page now !!!                    page.evaluate(function() {                        console.log(document.title);//!!! bug : if it may be log on the erp incurrent with kinds of reason(such as network status)                        //punch the clock                        //create clock event                        var clickEvent = document.createEvent("HTMLEvents");                        clickEvent.initEvent("click",false,true);                        document.getElementById('clockIn').dispatchEvent(clickEvent);                    });                    window.setTimeout(function() {                        console.log('punch completely , exiting');                        phantom.exit();                    },3000);                });            },3000);        });    },3000);});






0 1
原创粉丝点击