python-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()
     #这个网站加载有点慢所以都加了睡眠时间等待网站渲染
    time.sleep(8)
   #把句柄切换到课程的句柄
    try:
        b.switch_to_window(b.window_handles[1])
    except DeprecationWarning:
        print('')
    finally:
        b.find_element_by_xpath('//*[@id="&courseId=00DCE5A9AE5343DAA5F4ACFA725A9BD0&sectionId=6342E71EFA864996BD07AB5C99909948"]').click()
    time.sleep(8)
    #切回到学习数据页面然后打开第二门课程
    b.switch_to_window(b.window_handles[0])
    c2 = b.find_element_by_xpath('//tbody/tr[2]/td[7]/div/a').click()
    time.sleep(8)
    try:
        b.switch_to_window(b.window_handles[3])
    except DeprecationWarning:
        print('')
    finally:
        b.find_element_by_xpath('//*[@id="&courseId=13F7C9A2967D487B9CE01B6B1BC019F7&sectionId=FB9B94C89483419D8AE3FB94F5C57C03"]').click()
    time.sleep(8)

    b.switch_to_window(b.window_handles[0])
    c3 = b.find_element_by_xpath('//tbody/tr[3]/td[7]/div/a').click()
    time.sleep(8)
    try:
        b.switch_to_window(b.window_handles[5])
    except DeprecationWarning:
        print('')
    finally:
        b.find_element_by_xpath('//*[@id="https://80.cdn-vod.huaweicloud.com/asset/d7507eff0aff147b94325fca5e808086/play_video/index.m3u8&courseId=7AA7B6E81E504F8298E90E63B7FB3B20&coursewareId=D14267D5B196454E89300A8181972EDD&chapterId=3B9EEF77852E470F9F90739EAADCC862&sectionId=71990A2C1EAF40A5BED2B7600DB05AAA&cwId=D14267D5B196454E89300A8181972EDD&videoType=2"]').click()
    time.sleep(8)
        
    b.switch_to_window(b.window_handles[0])
    c4 = b.find_element_by_xpath('//tbody/tr[4]/td[7]/div/a').click()
    time.sleep(8)
    try:
        b.switch_to_window(b.window_handles[7])
    except DeprecationWarning:
        print('')
    finally:
        b.find_element_by_xpath('//*[@id="&courseId=919F8863B29949F0A1EA99291D008A84&sectionId=2184C73C6E554CD788B5306C213E3388"]').click()

if __name__ == '__main__':
    open_brower()


  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值