等以后有时间补上。
附上代码:
#! /usr/bin/env python
# coding:utf-8
#-----------------------------------------学号和密码自己填写。usage: python lab.py
# 如果是linux系统,可以配置crontab文件 crontab - e编辑保存以下内容
# 40 8 * * 1-5 /usr/bin/python /home/liyang/workspace/bug/lab.py
# 40 11 * * 1-5 /usr/bin/python /home/liyang/workspace/bug/lab.py
# 30 13 * * 1-5 /usr/bin/python /home/liyang/workspace/bug/lab.py
# 30 17 * * 1-5 /usr/bin/python /home/liyang/workspace/bug/lab.py
import urllib,urllib2,cookielib
import time
import logging
logging.basicConfig(filename='实验室自动签到日志.log',level=logging.DEBUG)
current_time= time.strftime('%H%M',time.localtime(time.time()))
hour_time=current_time[0:2]
params={'user.VUserId':'学号',
'user.VUserPassword':'密码',
"x":"",
"y":""
}
params=urllib.urlencode(params)
#设置cookie
cj=cookielib.CookieJar()
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
urllib2.install_opener(opener)
request2=urllib2.Request('http://www.buptcnc.cn/login/login',params)
i=int(hour_time)
if i in [8,13]:
print "开始执行签到"
print '正在登录......'
response2 = opener.open(request2)#post 数据
print "log success"
response3 = opener.open("http://10.104.5.63/LabManage/index/addattendance?vStuId=学号")
print "签到成功"
logging.info(time.ctime()+"签到成功")
else:
print "开始执行签离"
print '正在登录......'
response2 = opener.open(request2)#post 数据
response4 = opener.open("http://10.104.5.63/LabManage/index/addattendanceleave.action?vStuId=学号")
print "签离成功"
logging.info(time.ctime()+"签离成功")
源码下载
http://pan.baidu.com/s/1qWoAMGc