仅供学习使用,若使用过程中出现问题,概不负责
话不多说,直接上代码
ps:使用时需要安装对应的webdriver,自行摸索,Python库的安装之类的就不说了
import time
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
username = ''
password = ''
browser = webdriver.Chrome()
num = 10703
maxnum = 10802
for i in range(num,maxnum):
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()
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