Bootstrap

python刷******平台时间

仅供学习使用,若使用过程中出现问题,概不负责

话不多说,直接上代码
ps:使用时需要安装对应的webdriver,自行摸索,Python库的安装之类的就不说了
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
#设置用户名密码
username = ''
password = ''
#声明浏览器
browser = webdriver.Chrome()
#brower.get('http://moocs.unipus.cn/')
#开始的页面
num = 10703
#最大页面
maxnum = 10802
#print(brower.page_source)
for i in range(num,maxnum):
    #拼接URL
    url = 'http://moocs.unipus.cn/course/176/task/'+str(num)+'/show'
    browser.get(url)
    time.sleep(5)
    try:  
        #输入用户名
        user_input = browser.find_element_by_name('username')
        user_input.send_keys(username)
        #输入密码
        pass_input = browser.find_element_by_name('password')
        pass_input.send_keys(password)
        #点击登录
        button = browser.find_element_by_id('login')
        button.click()
        print('重新登陆')
    except NoSuchElementException:
        print('下一节:' + str(num))
    time.sleep(5)
    browser.refresh()
    time.sleep(5)
    #获取标题
    title = browser.find_element_by_class_name('dashboard-header')
    
    print(title.text[5:])
    
    back = (str)(title.text)
    back = back[-4:]
    
    if(back != '单元测试' and back != '思辨讨论'):
        browser.switch_to.default_content()

        #进到子frame,因为视频是单独的frame
        try:
            browser.switch_to_frame('task-content-iframe')
            text = browser.find_element_by_tag_name("iframe")       
            browser.switch_to.frame(text)   

            time.sleep(5)
            #获取视频时间
            times = browser.find_element_by_class_name('vjs-duration-display').text
            print(times)

            minutes, seconds= times.split(':')

            minutes = (int)(minutes)
            seconds = (int)(seconds)

            sleeptime = minutes * 60 + seconds
            #获取播放按钮
            button = browser.find_element_by_css_selector('.vjs-play-control.vjs-control.vjs-button')
            button.click()
            time.sleep(sleeptime)
        except NoSuchElementException:
            num = num - 1;
    else:
        time.sleep(5)

    num = num + 1
;