日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > python >内容正文

python

大一python题库刷题训练_python实现合工大试题库自动刷题

發(fā)布時間:2023/12/4 python 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 大一python题库刷题训练_python实现合工大试题库自动刷题 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1 #coding= utf-8

2 importre3 importrequests4 importxlrd5

6 save_url = "http://tkkc.hfut.edu.cn/student/exam/manageExam.do?1479131327464&method=saveAnswer"

7 #index用于提示題目序號

8 index = 1

9 headers = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64; rv:51.0) Gecko/20100101 Firefox/41.0",10 "Host": "tkkc.hfut.edu.cn",11 "X-Requested-With": "XMLHttpRequest",12 }13

14 ses =requests.session()15 ID = input("請輸入學(xué)號\n")16 Pwd = input("請輸入密碼\n")17 logInfo ={18 "logname": ID,19 "password": Pwd20 }21 login_url = "http://tkkc.hfut.edu.cn/login.do?"

22 res = ses.post(login_url, data=logInfo, headers=headers)23

24 #用于存放excel中question,answer鍵值對的字典

25 result =dict()26

27

28 #retries默認(rèn)為2,表示嘗試次數(shù)。以防某種原因,某次連接失敗

29 def craw(url, retries=2):30 try:31 b = ses.post(url, headers=headers)32 b.encoding = 'utf-8'

33 d =b.text34 title = re.findall(r'?(.*?)","', d, re.S)[0]35 returntitle36 exceptException as e:37 print(e)38 if retries >0:39 return craw(url, retries=retries - 1)40 else:41 print("get failed", index)42 return ''

43

44

45 #從字典中根據(jù)題目找到并返回答案

46 defanswer_func(t):47 return result.get(title, "Not Found")48

49

50 #將找到的答案提交給服務(wù)器

51 def submit(ans, id, id2, id3, id4, index, retries=2):52 dx = ["false", "false", "false", "false", "false"]53 try:54 if ans.find('A') != -1:55 dx[0] = "true"

56 if ans.find('B') != -1:57 dx[1] = "true"

58 if ans.find('C') != -1:59 dx[2] = "true"

60 if ans.find('D') != -1:61 dx[3] = "true"

62 if ans.find('E') != -1:63 dx[4] = "true"

64 if ans.find('正確') != -1:65 ans = "A"

66 if ans.find('錯誤') != -1:67 ans = "B"

68 data2 = {"examReplyId": id3,69 "examStudentExerciseId": id2,70 "exerciseId": id,71 "examId": id4,72 "DXanswer": ans,73 "PDanswer": ans,74 "DuoXanswerA": dx[0],75 "DuoXanswerB": dx[1],76 "DuoXanswerC": dx[2],77 "DuoXanswerD": dx[3],78 "DuoXanswerE": dx[4]}79 body = ses.post(save_url, data=data2, headers=headers)80 wb_data =body.text81 print(wb_data, index)82 exceptException as e:83 print(e)84 if retries >0:85 return submit(ans, id, id2, id3, id4, index, retries=retries - 1)86 else:87 print("get failed", index)88 return ''

89

90

91 #此變量用于判斷用戶是否要繼續(xù)刷課

92 finished =093

94 while finished ==0:95 start_url = input("請輸入測試頁面URL\n")96

97 myfile = xlrd.open_workbook('exercise.xls')98 lenOfXls =len(myfile.sheets())99

100 #讀取XLS中的題目和答案,存進(jìn)字典(將這段程序放在這,是因?yàn)楫?dāng)用戶有多門試題庫時,刷完一門,切換到另一門時,不用關(guān)閉程序只需切換題庫Excel即可)

101 for x inrange(0, lenOfXls):102 xls =myfile.sheets()[x]103 for i in range(1, xls.nrows):104 title =xls.cell(i, 0).value105 if x != 2:106 answer = xls.cell(i, 7).value107 else:108 answer = xls.cell(i, 2).value109 result[title] =answer110

111 body = ses.get(start_url, headers=headers)112 body.encoding = 'utf-8'

113 wb_data =body.text114 #print(wb_data)

115

116 urlId = re.findall(r'do\?(.*?)&method', start_url, re.S)[0]117

118 eval = re.findall(r'eval(.*?)]\);', wb_data, re.S)[0]119

120 examReplyId = re.findall(r'examReplyId=(.*?)&examId', wb_data, re.S)[0]121

122 examId = re.findall(r'', wb_data, re.S)[0]123

124 exerciseId = re.findall(r'exerciseId":(.*?),', eval, re.S)125

126 examSEId = re.findall(r'examStudentExerciseId":(.*?),', eval, re.S)127

128 examStudentExerciseId = re.findall(r'"examStudentExerciseId":(.*?),"exerciseId"',129 wb_data, re.S)[0]130

131 print(examStudentExerciseId)132 examStudentExerciseId =int(examStudentExerciseId)133

134 #id對應(yīng)exerciseID,id2對應(yīng)examStudetExerciseId

135 for id inexerciseId:136 next_url = r"http://tkkc.hfut.edu.cn/student/exam/manageExam.do?%s&method=getExerciseInfo&examReplyId=%s&exerciseId=%s&examStudentExerciseId=%d" %(137 urlId, examReplyId, id, examStudentExerciseId)138 title =craw(next_url)139 ans =answer_func(title)140 submit(ans, id, examStudentExerciseId, examReplyId, examId, index)141 #time.sleep(1)

142 index += 1

143 examStudentExerciseId = examStudentExerciseId + 1

144 #input函數(shù)獲取到的為字符串,所以進(jìn)行Type conversion

145 finished = int(input("繼續(xù)請輸入0,退出請輸入1\n"))

總結(jié)

以上是生活随笔為你收集整理的大一python题库刷题训练_python实现合工大试题库自动刷题的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。