浙江理工大学英语平台Unipus自动答题
生活随笔
收集整理的這篇文章主要介紹了
浙江理工大学英语平台Unipus自动答题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
思路分析:簡單的Web自動化,使用selenium完成簡單的拖拽填詞選擇即可
廢話不多說,直接上代碼
# coding=utf-8 import time from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.select import Selectprint("該程序僅用于Python程序學習交流") print('') print("目前只適用于藍色書,如有BUG請聯系作者") print('') print("請在黑窗口(非瀏覽器)輸入賬號和密碼") print('') print("程序執行過程中請不要操作瀏覽器") print('') print("程序執行完成后請手動訪問下面網址查看分數") print('') print("http://10.11.8.83/course07/gradebooklist.php") print('') print("按回車鍵繼續...") agree = input()driver = webdriver.Chrome(r'./../chromedriver.exe')driver.get('http://10.11.8.83') driver.minimize_window()# driver.find_element_by_name('tj_trnews').click() # driver.get('https://www.baidu.com') # driver.find_element_by_name('tj_trhao123').click()# navs = driver.find_elements_by_class_name('mnav') # for j in navs: # print(j) # # for index in range(len(navs)): # navs[index].click() # driver.back() # driver.refresh() # driver.forward() # driver.maximize_window() # driver.minimize_window() # driver.maximize_window()def login():name_input = driver.find_element_by_id('username')password_input = driver.find_element_by_id('password')username = input('請輸入學號:')password = input('請輸入密碼:')driver.maximize_window()name_input.clear()for i in username:# time.sleep(0.03)name_input.send_keys(i)for j in password:# time.sleep(0.03)password_input.send_keys(j)driver.find_element_by_xpath('//*[@id="LoginForm"]/table/tbody/tr[3]/td[2]/input').click()# time.sleep(0.5)# driver.get('http://10.11.8.83/login/hpindex_student.php')driver.refresh()courses = driver.find_elements_by_xpath('//*[@id="BookClassDIV"]/table/tbody/child::tr/td[2]/ul/li/a')for course in courses:if '讀寫3' in course.text:# print(type(course.get_attribute('href')))link = course.get_attribute('href')print(link[link.find('BookID=') + 7:link.find('BookID=') + 10])print(course.get_attribute('href'))print(course.text)# driver.get('http://10.11.8.83/book/book{}/index.php?Quiz=N&whichActionPage='.format(course.text))course.click()driver.refresh()return link[link.find('BookID=') + 7:link.find('BookID=') + 10]else:print('未找到相關課程!')returndef write_understanding(book_name, unit, answer):# answer應該是一個存儲有答案的字典url = 'http://10.11.8.83/book/book{}/uyu64mc.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 6, 4)driver.get(url)driver.find_element_by_id('TR_0')for i in range(8):# print('//*[@id="TR_' + str(i) + '"]/td[2]/input')inputs = driver.find_elements_by_xpath('//*[@id="TR_' + str(i) + '"]/td[2]/input')# //*[@id="TR_0"]/td[1]/inputfor item in inputs:if item.get_attribute('value') == answer[i]:item.click()break# time.sleep(0.3) # 每做一題休息半秒inputs = driver.find_elements_by_xpath('//*[@id="TR_' + str(i) + '"]/td[1]/input')for item in inputs:if item.get_attribute('value') == answer[i]:item.click()break# driver.find_element_by_xpath("//div[contains(@class,'submit')]/a").click()driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def a_write_word_in_use(book_name, unit, answer):# answer應該是一個存儲有答案的字典url = 'http://10.11.8.83/book/book{}/uyu27blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 2, 7)driver.get(url)for i in range(10):blank = driver.find_element_by_id('Blank_' + str(i) + '_0')blank.clear()for letter in answer[i]:blank.send_keys(letter)# time.sleep(0.03)# time.sleep(0.1)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()# tip = driver.find_element_by_xpath("/html/body/div[3]/div[2]/p[1]")# if 'Done with this activity' not in tip.text:try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def a_word_building_practice_one(book_name, unit, answer):# answer應該是一個存儲有答案的字典url = 'http://10.11.8.83/book/book{}/uyu29blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 2, 9)driver.get(url)for i in range(12):blank = driver.find_element_by_id('Blank_' + str(i) + '_0')blank.clear()for letter in answer[i]:blank.send_keys(letter)# time.sleep(0.03)# time.sleep(0.3)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()# tip = driver.find_element_by_xpath("/html/body/div[3]/div[2]/p[1]")# if 'Done with this activity' not in tip.text:try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def a_word_building_practice_two(book_name, unit, answer):# answer應該是一個存儲有答案的字典url = 'http://10.11.8.83/book/book{}/uyu27blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 2, 10)driver.get(url)for i in range(12):blank = driver.find_element_by_id('Blank_' + str(i) + '_0')blank.clear()for letter in answer[i]:blank.send_keys(letter)# time.sleep(0.03)# time.sleep(0.3)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()# tip = driver.find_element_by_xpath("/html/body/div[3]/div[2]/p[1]")# if 'Done with this activity' not in tip.text:try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def a_blanked_close(book_name, unit, answer):url = "http://10.11.8.83/book/book{}/uyu211drop.php?UnitID={}&SectionID={}&SisterID={}".format(book_name, unit, 2, 11)driver.get(url)for i in range(len(answer)):# 起點start = driver.find_element_by_xpath('//*[@id="list_' + str(ord(answer[i]) - ord('A') + 1) + '"]')# 終點end = driver.find_element_by_xpath('//*[@id="Item_0_' + str(i) + '"]')actions = ActionChains(driver)actions.click_and_hold(start)actions.drag_and_drop(start, end)# 執行actions.perform()driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passdef a_expressions_in_use(book_name, unit, answer):# answer應該是一個存儲有答案的字典url = 'http://10.11.8.83/book/book{}/uyu27blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 2, 12)driver.get(url)for i in range(8):blank = driver.find_element_by_id('Blank_' + str(i) + '_0')blank.clear()for letter in answer[i]:blank.send_keys(letter)# time.sleep(0.03)# time.sleep(0.1)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()# tip = driver.find_element_by_xpath("/html/body/div[3]/div[2]/p[1]")# if 'Done with this activity' not in tip.text:try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def write_word_in_use(book_name, unit, answer):# answer應該是一個存儲有答案的字典url = 'http://10.11.8.83/book/book{}/uyu27blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 6, 6)driver.get(url)for i in range(10):blank = driver.find_element_by_id('Blank_' + str(i) + '_0')blank.clear()for letter in answer[i]:blank.send_keys(letter)# time.sleep(0.03)# time.sleep(0.1)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()# tip = driver.find_element_by_xpath("/html/body/div[3]/div[2]/p[1]")# if 'Done with this activity' not in tip.text:try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def write_expressions_in_use(book_name, unit, answer):# answer應該是一個存儲有答案的字典# 注意這個地方可能出現某一題有兩個空,要考慮修改一下url = 'http://10.11.8.83/book/book{}/uyu27blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 6, 7)driver.get(url)for i in range(8):blank = driver.find_element_by_id('Blank_' + str(i) + '_0')blank.clear()for letter in answer[i]:blank.send_keys(letter)# time.sleep(0.1)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passdef element_dragging(book_name, unit, answer):target_answer = []for item in answer:# print(item.index)# print(item.split(" "))target_answer.append(item.split(" ")[1])url = "http://10.11.8.83/book/book{}/uyu72drag.php?UnitID={}&SectionID={}&SisterID={}".format(book_name, unit, 7, 2)driver.get(url)blocks = driver.find_elements_by_xpath('//*[@id="firstlist"]/li')start_answer = []for i in range(len(blocks)):start_answer.append(blocks[i].text.split(' ')[1])target_answer_list = [[i+1, target_answer[i]] for i in range(len(blocks))]# print(target_answer_list)# print(start_answer)start_answer_list = []for i in range(len(blocks)):j = 0for j in range(len(blocks)):if start_answer[i] in target_answer_list[j]:breakstart_answer_list.append([j+1, start_answer[i]])# print(target_answer)# print(start_answer_list)for i in range(0, len(blocks)-1):for j in range(0, len(blocks)-1-i):if start_answer_list[j][0] > start_answer_list[j+1][0]:temp = start_answer_list[j]start_answer_list[j] = start_answer_list[j+1]start_answer_list[j+1] = tempprint("swap")print(start_answer_list[j])print(start_answer_list[j+1])blocks = driver.find_elements_by_xpath('//*[@id="firstlist"]/li')ActionChains(driver).drag_and_drop_by_offset(blocks[j], 0, 50).perform()time.sleep(0.5)# print(start_answer_list)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passdef element_select(book_name, unit, answer):url = "http://10.11.8.83/book/book{}/uyu73select.php?UnitID={}&SectionID={}&SisterID={}".format(book_name, unit, 7, 2)if unit == 8:url = "http://10.11.8.83/book/book{}/uyu72select.php?UnitID={}&SectionID={}&SisterID={}".format(book_name, unit, 7, 2)driver.get(url)selects = driver.find_elements_by_xpath("//div[@class='zw-k']//select")for i in range(len(answer)):# selects = driver.find_elements_by_xpath("//div[@class='zw-k']//select")Select(selects[i]).select_by_visible_text(answer[i])driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passdef collection_practice_one(book_name, unit, answer):# answer應該是一個存儲有答案的字典if unit == 3:element_dragging(book_name, unit, answer)returnif unit == 4 or unit == 8:element_select(book_name, unit, answer)returnif unit == 5:url = 'http://10.11.8.83/book/book{}/uyu66blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 7, 2)driver.get(url)blank = driver.find_elements_by_xpath('//*[@id="QuestionForm"]/table/tbody//input')for i in range(len(answer)):blank[i].clear()for letter in answer[i]:blank[i].send_keys(letter)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passfinally:returnurl = 'http://10.11.8.83/book/book{}/uyu72blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 7, 2)driver.get(url)for i in range(len(answer)):for j in range(3):blank = driver.find_element_by_id('Blank_' + str(i) + '_' + str(j) + '')blank.clear()for letter in answer[i][j]:blank.send_keys(letter)# time.sleep(0.03)# time.sleep(0.3)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def collection_practice_two(book_name, unit, answer):# answer應該是一個存儲有答案的字典if unit == 8:url = "http://10.11.8.83/book/book{}/uyu72select.php?UnitID={}&SectionID={}&SisterID={}".format(book_name, unit, 7, 3)driver.get(url)selects = driver.find_elements_by_xpath("//div[@class='zw-k']//select")for i in range(len(answer)):# selects = driver.find_elements_by_xpath("//div[@class='zw-k']//select")Select(selects[i]).select_by_visible_text(answer[i])driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passfinally:returnurl = 'http://10.11.8.83/book/book{}/uyu66blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 7, 3)if unit == 3:url = 'http://10.11.8.83/book/book{}/uyu72blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, unit, 7, 3)driver.get(url)if unit == 3:for i in range(len(answer)):blank = driver.find_elements_by_xpath('//*[@class="zw-k"]//input')blank[i].clear()for letter in answer[i]:blank[i].send_keys(letter)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passfinally:returnif unit == 4 or unit == 5:for i in range(len(answer)):blank = driver.find_elements_by_xpath('//*[@id="QuestionForm"]/table//input')blank[i].clear()for letter in answer[i]:blank[i].send_keys(letter)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passfinally:returnfor i in range(len(answer)):blank = driver.find_element_by_id('Blank_0_' + str(i))blank.clear()for letter in answer[i]:blank.send_keys(letter)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)def common_use(book_name, unit, answer):# answer應該是一個存儲有答案的字典url = 'http://10.11.8.83/book/book{}/uyu66blank.php?UnitID={}&SectionID={}&SisterID={}'.format(book_name, 3, 7, 3)driver.get(url)blank = driver.find_elements_by_xpath("//input[@class='x-su-text-1']")for i in range(len(answer)):blank[i].clear()blank[i].send_keys(answer[i])# time.sleep(0.03)# time.sleep(0.3)driver.find_element_by_xpath("//div[contains(@class,'submit')]").click()# tip = driver.find_element_by_xpath("/html/body/div[3]/div[2]/p[1]")# if 'Done with this activity' not in tip.text:try:driver.find_element_by_class_name('layui-layer-btn0').click()except:pass# time.sleep(1)book = login() a_write_word_in_use_keys = [['whereby', 'pursuit ', 'inhibit', 'maintain', 'patriotic', 'transcended ', 'endeavors', 'dedication', 'prestige', 'nominate'],['intervene', 'underestimate', 'recede', 'deem', 'bleak', 'appraise', 'paralyzed', 'symptoms', 'dismay', 'brink'],['integral', 'cherish', 'afflicted', 'noteworthy', 'portray', 'compliment', 'domain', 'anonymous', 'conscientious', 'perpetual']] a_word_building_practice_one_keys = [['inhabit', 'participant', 'attendant', 'pollutant', 'descendant', 'contestant', 'tolerant', 'resultant', 'neglectful', 'resourceful', 'boastful','respectful'],['dominance', 'avoidance', 'reliance', 'acquaintance', 'clearance', 'annoyance', 'admittance', 'resemblance', 'assurance', 'bored', 'privileged','distracted'],['generalize', 'normalize', 'publicize', 'minimize', 'immunize', 'mobilize', 'investor', 'dictator', 'conqueror', 'investigator', 'moderator', 'elevate']] a_word_building_practice_two_keys = [['resultant', 'tolerant', 'pollutants', 'inhabited', 'contestants', 'descendants', 'attendants', 'respectful', 'participants', 'neglectful', 'resourceful','boastful'],['bored', 'privileged', 'assurance', 'dominance', 'avoidance', 'acquaintance', 'reliance', 'clearance', 'distracted', 'annoyance', 'admittance','resemblance'],['normalize', 'moderator', 'immunized', 'investors', 'mobilize', 'conqueror', 'elevate', 'publicizes', 'investigator', 'minimized', 'generalize','dictator']] a_blanked_close_keys = [['F', 'G', 'H', 'J', 'E', 'A', 'N', 'I', 'K', 'M'],['K', 'D', 'H', 'J', 'I', 'O', 'G', 'A', 'N', 'C'],['C', 'I', 'F', 'L', 'A', 'H', 'K', 'N', 'E', 'B']] a_expressions_in_use_keys = [['removed from', 'failed in', 'in the pursuit of', 'deviated from', 'precludes', 'triumph over', 'work their way into', 'written off'],['pulled to a stop', 'black out', 'pop up', 'stopped short', 'plowed through', 'threw himself into', 'let yourself go', 'grabbed for'],['embark on', 'be deprived of', 'turn down', 'taken captive', 'live on', 'share in', 'was stricken by', 'led by example']] write_understanding_keys = [['c', 'b', 'a', 'd', 'd', 'b', 'c', 'd'],['a', 'd', 'c', 'b', 'd', 'c', 'd', 'a'],['d', 'c', 'd', 'a', 'b', 'c', 'd', 'd'],['c', 'a', 'b', 'd', 'a', 'd', 'c', 'b'],['c', 'd', 'b', 'a', 'b', 'd', 'b', 'a'],['b', 'a', 'a', 'd', 'c', 'b', 'c', 'd']] write_word_in_use_keys = [['indulge', 'propelling', 'aggravated', 'dazzled', 'alleviating', 'renowned', 'eloquent', 'destined', 'scorned', 'applause'],['vertical', 'evaporate', 'plight', 'intent', 'abort', 'vulnerable', 'proximity', 'evoke', 'lofty', 'necessitate'],['skeptical', 'coincidence', 'mounted', 'contrive', 'simulated', 'manifest', 'divert', 'infected', 'upgraded', 'temperament'],['ethnic', 'conceive', 'presumed', 'despised', 'irritate', 'disregarded', 'downside', 'venerable', 'susceptible', 'suppress'],['Rash', 'specialty', 'ponder', 'utilize', 'pierce', 'bias', 'ensue', 'impart', 'infectious', 'hospitality'],['intermediate', 'sniff', 'contention', 'articulate', 'scrutiny', 'constrict', 'contempt', 'unanimous', 'rear', 'administer']] write_expressions_in_use_keys = [['up', 'in', 'on', 'up', 'to', 'on', 'as', 'out'],['in the event of', 'immune to', 'settled back', 'on board', 'in position', 'was', 'for sure', 'hint of'],['on', 'in', 'as', 'into', 'to', 'to', 'with', 'under'],['from', 'from', 'with', 'into', 'to', 'into', 'for', 'off'],['out', 'on', 'away', 'to', 'to', 'in', 'away', 'up'],['to', 'through', 'off', 'down', 'to', 'out', 'under', 'back']] collection_practice_one_keys = [[['repeated', 'overwhelming', 'immense'], ['heroic', 'sound', 'substantial'], ['attained', 'fueled', 'achieve']],[['massive', 'incredible', 'terrible'], ['relaxed', 'absolutely', 'unremarkable']],['internationally famous', 'rigorous schedule', 'jeopardize hope','emotionally draining', 'physically dangerous', 'overwhelming misery','perpetually signify', 'conspicuous interest', 'repeatedly try'],['overly fearful', 'disorienting diversity', 'solo travel','swap stories', 'globalized world', 'foreign travel'],['prideful', 'high', 'special', 'trivial', 'sole', 'friendly', 'cheerful', 'instant', 'charitable'],['versatile', 'shatter', 'unquestioning', 'stony', 'hair-tearing', 'substandard']] collection_practice_two_keys = [['sudden', 'opportunity', 'immense', 'obstacles', 'amazing', 'determination', 'profound', 'difficulties', 'overwhelming', 'failures', 'poverty','-stricken','substantial', 'hardships', 'repeated', 'misfortunes', 'sheer', 'persistence', 'dazzle', 'audience', 'achieve', 'fame', 'strong', 'will'],['emotionally', 'impossible', 'amazing', 'power', 'visibly', 'frightened', 'incredible', 'impact', 'impromptu', 'rescues', 'instantaneously', 'hysterical','calm', 'confidence', 'true', 'courage', 'massive', 'waves', 'would-be', 'rescue', 'vicious', 'waves', 'rough', 'water'],['internationally', 'committed', 'compassionate', 'repeatedly', 'thrill', 'terrific', 'overwhelming', 'desperate', 'physically', 'rectified', 'personal','emotionally'],['exotic', 'places', 'lovely', 'dream', 'multinational', 'excursions', 'pleasant', 'experiences', 'foreign', 'travel', 'valuable', 'open-mindedness','ample', 'opportunities', 'disorienting', 'diversity', 'local', 'folklore', 'swap', 'stories', 'modern', 'aviation', 'credible', 'insights'],['unhappy', 'personally', 'optimum', 'truly', 'monetary', 'sole', 'personal', 'trivial', 'special', 'high', 'friendly', 'cheerful'],['hair-tearing', 'negative', 'substandard', 'stony', 'perfect', 'unilateral', 'shatter', 'secretly', 'unquestioning', 'true', 'intensify', 'ultimate']] common_use_keys = ['internationally*', 'committed*', 'compassionate*', 'repeatedly*', 'thrill*', 'terrific*', 'overwhelming*', 'desperate*', 'physically*','rectified*', 'personal*', 'emotionally*']for k in range(1, 9):# a_write_word_in_use(book, k, a_write_word_in_use_keys[k - 1])# a_word_building_practice_one(book, k, a_word_building_practice_one_keys[k - 1])# a_word_building_practice_two(book, k, a_word_building_practice_two_keys[k - 1])# a_blanked_close(book, k, a_blanked_close_keys[k - 1])# a_expressions_in_use(book, k, a_expressions_in_use_keys[k - 1])if k == 6 or k == 7:continueif k == 8:write_understanding(book, k, write_understanding_keys[k - 3])write_word_in_use(book, k, write_word_in_use_keys[k - 3])write_expressions_in_use(book, k, write_expressions_in_use_keys[k - 3])collection_practice_one(book, k, collection_practice_one_keys[k - 3])collection_practice_two(book, k, collection_practice_two_keys[k - 3])write_understanding(book, k, write_understanding_keys[k - 1])write_word_in_use(book, k, write_word_in_use_keys[k - 1])write_expressions_in_use(book, k, write_expressions_in_use_keys[k - 1])collection_practice_one(book, k, collection_practice_one_keys[k - 1])collection_practice_two(book, k, collection_practice_two_keys[k - 1])driver.get('http://10.11.8.83/course07/gradebooklist.php') print("程序執行完成!!!") print("請認真核對您的分數,如有問題請聯系作者") time.sleep(300)總結
以上是生活随笔為你收集整理的浙江理工大学英语平台Unipus自动答题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Vmtools安装和使用
- 下一篇: 《商界》名言