2025-05-24 02:47:28python-JS优学网课挂学时脚本
老师要求每挂满150分钟的课程,然后就想着写一个脚本来挂学时,使用了selenium来模拟浏览器行为来写的一个挂网课脚本。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
import time
uname = ''
paswd = ''
def open_brower():
b = webdriver.Chrome()
#打开经世优学网站
b.get('http://study.huatec.com/')
#设置等待时间直到找到元素
user = WebDriverWait(b,10).until(lambda b:b.find_element_by_id('username'))
user.clear()
user.send_keys(uname)
pwd = WebDriverWait(b,10).until(lambda b:b.find_element_by_id('password'))
pwd.clear()
pwd.send_keys(paswd)
#点击登录
b.find_element_by_class_name('btn-success').click()
time.sleep(10)
#用time模块来睡眠10S,让网站渲染出来
std_data = b.find_element_by_link_text('学习数据')
std_data.click()
#打开第一门课程
c1 = WebDriverWait(b,10).until(lambda b:b.find_element_by_xpath('//tbody/tr[1]/td[7]/div/a'))
c1.click()