主要是对cookie的处理,对正则表达式的应用
多大学用的都是urp的吧,帮同学评教的时候也改进了许多。 正常评教时每个网页需要等待2分钟,程序里没有激活js直接就可以秒评。
ps: urp的网页写的这都是啥啊! wjbm、bgr、pgnr完全看不懂是什么意思… 就看懂一个 ,密码是mm….
代码
#-*-coding:utf-8-*-
#python3.4 projiet
import http.cookiejar, urllib.request,re,time
header = {
'Connection': 'Keep-Alive',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.8,zh-Hans-CN;q=0.5,zh-Hans;q=0.3',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko',
'Accept-Encoding': 'gzip, deflate',
# 'Host': '',
}
#//
#如果要使用的话修改这里的三个参数
index_url = '' #登录网址
teacher_list_url = '' #评教名单网址
paper_url = '' #评教页面网址
submit_url = '' #评教提交表单网址
#//
def get_paper_form_postdata(wjbm,bpr,pgnr,L = []):
if len(L)==0:
postDict = {
'wjbm':wjbm,
'bpr':bpr,
'pgnr':pgnr,
'oper':'wjShow',
#'wjmc':'2014-2015-2%CC%E5%D3%FD%BF%CE', #fuck ! what the hell is that!
#'bprm':'%CE%E2%B1%F6', #fuck ! what the hell is that!
#'pgnrm':'%CC%E5%D3%FD%A3%A8%B6%FE%A3%A9', #fuck ! what the hell is that!
'pageSize':'20',
'page':'1',
'currentPage':'1',
'pageNo':''
}
else:
postDict = {
'wjbm':wjbm,
'bpr':bpr,
'pgnr':pgnr,
# 'zgpj':
}
for x in L:
postDict[x] = '10_1' #默认全都是最好想修改去urp看每个评级的值
postData = urllib.parse.urlencode(postDict).encode()
return postData
print('默认都是好评,如果不想给那个老师都好,请登陆网站先对那个老师进行评教!')
id = input('Input your number:')
password = input('please enter your password: ')
postDict = {
b'zjh': id,
b'mm': password,
}
postData = urllib.parse.urlencode(postDict).encode()
cj = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
r = opener.open(index_url,postData) #1.login
#get cookie
r = opener.open(teacher_list_url) #2.get the page list
html = r.read().decode('GBK') #get teacher list
html_select = re.findall('<img name="(\d+)#@(\d+)#@(.+?)#@.+?#@(.+?)#@(\d+?)"',html)
for n in range(len(html_select)):
wjbm = html_select[n][0]
bpr = html_select[n][1]
print('正在评价:',html_select[n][2],html_select[n][3])
html_select[n][3]
pgnr = html_select[n][4]
postData = get_paper_form_postdata(wjbm,bpr,pgnr)
r = opener.open(paper_url,postData)
r = r.read().decode('GBK') #page list
flag = re.findall('name="(\d+)"',r)
a = [flag[0]]
temp = flag[0]
for i in range(len(flag)):
if temp != flag[i]:
a.append(flag[i])
temp = flag[i]
postData = get_paper_form_postdata(wjbm,bpr,pgnr,L = a)
r = opener.open(submit_url,postData)
time.sleep(0.5)
print('成功!')
print('评教完毕!')
print('如有问题,请反馈给 277303565@qq.com')
input()