Unipus读写课程做题工具
生活随笔
收集整理的這篇文章主要介紹了
Unipus读写课程做题工具
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
很簡短的目錄
- Unipus讀寫課程做題工具
- 小小的原理
- 代碼
- 這里是效果~
- 更改做題頁面
Unipus讀寫課程做題工具
小小的原理
實際方法就是模擬人工輸入尋找對應文本框(笑)
并且利用的是完成作業的用戶可以Answer可以展示正確答案
小細節,對方的正確與否不影響你的正確率哦~
python很爛,現學的
記得安裝 selenium庫和對應瀏覽器插件
這里我使用的是Edge和Chrome
注:默認不會打開瀏覽器,自動做題直至結束
可以選擇debug=0開啟 debug 會顯示瀏覽器并在每道題結束后進行暫停以便人工核對
代碼
下面是寫的垃圾代碼
import time from selenium import webdriver from msedge.selenium_tools import EdgeOptions, Edge from selenium.webdriver.common.action_chains import ActionChains from selenium.webdriver.support.select import Selectdebug=1def login(driver,bookname):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://211.81.52.7/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 bookname 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://211.81.52.7/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 isElementExist(browser,xpath):flag=Truetry:browser.find_element_by_xpath(xpath)return flagexcept:flag=Falsereturn flagdef setBlank(book_name,unit,section,sister):url='http://{}/book/book{}/uyu27blank.php?UnitID={}&SectionID={}&SisterID={}'.format(ip,book_name, unit, section, sister)driver.get(url)driver2.get(url)driver2.find_element_by_xpath("/html/body/div[3]/div[4]/a").click()blankrow1 = driver.find_elements_by_class_name("x-su-text-1")blankrow2 = driver2.find_elements_by_xpath(" //*[@class='x-su-text-1'] | //*[@class='zqda']")if isElementExist(driver,"/html/body/div[3]/div[3]")==False:returnbutton = driver.find_element_by_xpath("/html/body/div[3]/div[3]")offest=0for blank1 in blankrow1:blank2=blankrow2[blankrow1.index(blank1)+offest]if(len(blankrow2)>blankrow1.index(blank1)+offest+1):blank3=blankrow2[blankrow1.index(blank1)+offest+1]else:blank3=blank2blank1.clear()if(blank3.get_attribute("class")=="x-su-text-1"):blank1.send_keys(blank2.get_attribute("value"))else:offest+=1blank1.send_keys(blank3.text[1:len(blank3.text)-1])print("uyu27blank.php",unit,section,sister)if(debug==0):answer=input()button.click()try:driver.find_element_by_class_name('layui-layer-btn0').click()except:passdef dragBankedcloze(book_name,unit):url = 'http://{}/book/book{}/uyu211drop.php?UnitID={}&SectionID={}&SisterID={}'.format(ip,book_name, unit, 2, 11)driver.get(url)driver2.get(url)driver2.find_element_by_xpath("/html/body/div[3]/div[7]/a/div").click()blankrow1 = driver.find_elements_by_xpath(" //*[@class='droppable ui-droppable' and @type='text']")offest=0blankrow2 = driver2.find_elements_by_xpath(" //*[@class='droppable ui-droppable' and @type='text'] | //*[@class='tkt-c']")for blank1 in blankrow1:blank2=blankrow2[blankrow1.index(blank1)+offest]if(len(blankrow2)>blankrow1.index(blank1)+offest+1):blank3=blankrow2[blankrow1.index(blank1)+offest+1]else:blank3=blank2if(blank3.get_attribute("class")=="droppable ui-droppable"):driver.execute_script("arguments[0].value = arguments[1];",blank1,blank2.get_attribute("value"))else:offest+=1driver.execute_script("arguments[0].value = arguments[1];",blank1,blank3.text[1:len(blank3.text)-1])print("uyu211drop.php ",unit)if(debug==0):answer=input()try:button = driver.find_element_by_xpath("/html/body/div[3]/a/div")button.click()driver.find_element_by_class_name('layui-layer-btn0').click()except:passdef setUnderstanding(book_name, unit):url = 'http://{}/book/book{}/uyu64mc.php?UnitID={}&SectionID={}&SisterID={}'.format(ip,book_name, unit, 6, 4)driver.get(url)driver2.get(url)driver2.find_element_by_xpath("/html/body/div[4]/div[3]/div[4]").click()driver.find_element_by_id('TR_0')for i in range(8):inputs = driver.find_elements_by_xpath('//*[@id="TR_' + str(i) + '"]/td[2]/input')outputs = driver2.find_elements_by_xpath('//*[@id="TR_' + str(i) + '"]/td[2]/input')# //*[@id="TR_0"]/td[1]/inputfor item in inputs:item2=outputs[inputs.index(item)]if item2.get_attribute('checked'):item.click()break# time.sleep(0.3) # 每做一題休息半秒 inputs = driver.find_elements_by_xpath('//*[@id="TR_' + str(i) + '"]/td[1]/input')outputs = driver2.find_elements_by_xpath('//*[@id="TR_' + str(i) + '"]/td[1]/input')# //*[@id="TR_0"]/td[1]/inputfor item in inputs:item2=outputs[inputs.index(item)]if item2.get_attribute('checked'):item.click()break# driver.find_element_by_xpath("//div[contains(@class,'submit')]/a").click()print("uyu64mc.php ",unit)if(debug==0):answer=input()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 setBlankTK(book_name,unit):url='http://{}/book/book{}/uyu29blank.php?UnitID={}&SectionID={}&SisterID={}'.format(ip,book_name, unit, 2, 9)driver.get(url)driver2.get(url)driver2.find_element_by_xpath("/html/body/div[3]/div[3]/div[2]").click()blankrow1 = driver.find_elements_by_xpath("//*[@class='tk']/*[1]")blankrow2 = driver2.find_elements_by_xpath("//*[@class='wt-3']/*[@class='dc']")if isElementExist(driver,"/html/body/div[3]/div[2]/div[2]") == False:returnfor blank1 in blankrow1:blank2=blankrow2[blankrow1.index(blank1)]blank1.clear()strlist=blank2.text.split(' / ')blank1.send_keys(strlist[0])print("uyu29blank.php",unit)if(debug==0):answer=input()try:button = driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[2]")button.click()driver.find_element_by_class_name('layui-layer-btn0').click()except:pass#—————————————————————————————————————— print('unipus互助 by:Tricrystal') bookname=input('輸入需要完成的書名(eg:讀寫2):') ip=input('輸入unipus的ip地址 (eg:1.1.1.1) :') print('開啟瀏覽器Ing....') chrome_options = webdriver.ChromeOptions() chrome_options.add_argument('log-level=3') if debug!=0:chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu')chrome_options.add_experimental_option('excludeSwitches', ['enable-logging']) driver = webdriver.Chrome(chrome_options=chrome_options) driver.get('http://{}'.format(ip)) driver.minimize_window()edge_options = EdgeOptions() edge_options.use_chromium = True if debug!=0:edge_options.add_argument('headless') edge_options.add_argument('disable-gpu')edge_options.add_experimental_option('excludeSwitches', ['enable-logging']) edge_options.add_argument('log-level=3') driver2 = Edge(options=edge_options) driver2.get('http://{}'.format(ip)) driver2.minimize_window()print('瀏覽器開啟完畢') print('登錄待完成用戶') book = login(driver,bookname) print('登錄已完成用戶') login(driver2,bookname) i=1 while i!=8:dragBankedcloze(book,i)setBlankTK(book,i)setUnderstanding(book,i)#這里根據你自己的書的結構更改setBlank(book,i,2,7) setBlank(book,i,2,10)setBlank(book,i,6,6)setBlank(book,i,6,7)setBlank(book,i,7,3)setBlank(book,i,2,12)i+=1 driver.get("http://{}/book/book138/recordsummary.php".format(ip)) driver2.get("http://{}/book/book138/recordsummary.php".format(ip)) print('已經做完了呦,記得檢查哦')這里是效果~
上面為需要寫的人,下面為已寫的人
運行中界面 首行為頁面 第二行為 unitID 第三行為 SectionID 第四行為 SisterID
更改做題頁面
http://xx.xx.xx.xx/book/book138/uyu33.php?UnitID=3&SectionID=3&SisterID=3
其中可通用的目前只有uyu27blank,其中后面的三個數字參數分別為UnitID,SectionID,SisterID。
有問題可以發郵箱到 miku_mi@foxmail.com
總結
以上是生活随笔為你收集整理的Unipus读写课程做题工具的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 使用urllib发起请求- urlope
- 下一篇: 在OpenCV里使用图片修复