• 学习笔记


    from selenium import webdriver
    
    from selenium.webdriver.common.by import By
    
    import time
    
    
    TIME_FOR_LOGIN=30
    
    TIME_FOR_READING=20#70秒阅读完一篇文章
    TIME_FOR_VEDIO=300#5分钟看一个视频
    TIME_FOR_AJAX=5
    PAPER_START=6
    PAPER_COUNT=1#阅读文章数8篇
    VIDEO_START=6
    VIDEO_COUNT=6#观看视频数10个
    VIDEO_PAGE_INDEX=2#翻到第几页
    
    browser=webdriver.Chrome()
    
    
    ###################文章阅读部分
    
    browser.get('https:///index.html')
    
    time.sleep(TIME_FOR_LOGIN)
    
    browser.switch_to_window(browser.window_handles[0])
    
    titles=browser.find_elements(By.ID,'C3ciwhpvu5ck00')
    
    
    
    for i in range(1,3):
    
         js="window.scrollTo("+str((i-1)/10)+"*document.body.scrollHeight,"+str(i/10)+"*document.body.scrollHeight)"
    
         print(js)
    
         browser.execute_script(js)
    
         time.sleep(TIME_FOR_READING)
    
    
    paper_count=0
    
    
    for title in titles:
    
         paper_count=paper_count+1
    
         if(  paper_count>=PAPER_START and paper_count<=PAPER_START+PAPER_COUNT+1):
              title.click()
    
              time.sleep(TIME_FOR_AJAX)
    
              browser.switch_to_window(browser.window_handles[1])
    
              for i in range(1,11):
    
                   js="window.scrollTo("+str((i-1)/10)+"*document.body.scrollHeight,"+str(i/10)+"*document.body.scrollHeight)"
    
                   print(title.text+'文章阅读进度:'+str(i*10)+'%    '+js)
    
                   browser.execute_script(js)
    
                   time.sleep(TIME_FOR_READING)
    
    
              browser.close()
              browser.switch_to_window(browser.window_handles[0])
    
              
    #####################视频学习部分
    browser.get('https:///4426aa87b0b64ac671c96379a3a8bd26/db086044562a57b441c24f2af1c8e101.html')
    
    time.sleep(TIME_FOR_LOGIN)
    browser.switch_to_window(browser.window_handles[0])
    
    #浏览指定专题
    btns=browser.find_elements_by_class_name('radio-inline')
    for btn in btns:
         print(btn.text)
         if(btn.text=='学习专题报道'):
              btn.click()
    browser.switch_to_window(browser.window_handles[0])         
    #浏览指定页码
    #nextpage=browser.find_elements_by_class_name('next')
    #for i in range(1,VIDEO_PAGE_INDEX):
    #    nextpage.click()
    #    time.sleep(TIME_FOR_AJAX)
    
    #browser.switch_to_window(browser.window_handles[0])
    
    
    
    titles=browser.find_elements_by_class_name('word-item')
    
    v_count=0
    videoindex=0
    
    
    for title in titles:
         v_count=v_count+1
         videoindex=v_count // 2+1
         if(v_count % 2==1 and videoindex>= VIDEO_START and videoindex<=VIDEO_START+VIDEO_COUNT):
              title.click()
    
              time.sleep(TIME_FOR_AJAX)
    
              browser.switch_to_window(browser.window_handles[1])
    
              time.sleep(TIME_FOR_VEDIO)
              browser.close()
              browser.switch_to_window(browser.window_handles[0])
    
    browser.close()
    

      

  • 相关阅读:
    EntityFramework ,ef 介绍
    MVC controller and View
    MVC 模型
    mvc 控制器,视图,Razor 语法
    MVC 安装
    MVC 介绍
    vue 3.0 项目搭建移动端 (三) computed 和 methods 和 watch
    vue 3.0 项目搭建移动端 (二) Vue-router: router-link 与 router-view keep-alive
    添加网络js文件
    过滤 filter
  • 原文地址:https://www.cnblogs.com/nextseven/p/10482473.html
Copyright © 2020-2023  润新知