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 Select

debug=1

def 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('未找到相关课程!')
        return


def isElementExist(browser,xpath):
    flag=True
    try:
        browser.find_element_by_xpath(xpath)
        return flag
    except:
        flag=False
        return flag


def 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:
        return
    button = driver.find_element_by_xpath("/html/body/div[3]/div[3]")
    offest=0
    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=blank2
        blank1.clear()
        if(blank3.get_attribute("class")=="x-su-text-1"):
            blank1.send_keys(blank2.get_attribute("value"))
        else:
            offest+=1
            blank1.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:
        pass

def 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=0
    blankrow2 = 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=blank2
        if(blank3.get_attribute("class")=="droppable ui-droppable"):
            driver.execute_script("arguments[0].value = arguments[1];",blank1,blank2.get_attribute("value"))
        else:
            offest+=1
            driver.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:
        pass

def 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]/input
        for 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]/input
        for 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:
        return
    for 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
运行中界面 首行为页面 第二行为 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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Tricrystal

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值