zoukankan      html  css  js  c++  java
  • 学习笔记

    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()
    

      

  • 相关阅读:
    NBUT 1120 Reimu's Teleport (线段树)
    NBUT 1119 Patchouli's Books (STL应用)
    NBUT 1118 Marisa's Affair (排序统计,水)
    NBUT 1117 Kotiya's Incantation(字符输入处理)
    NBUT 1115 Cirno's Trick (水)
    NBUT 1114 Alice's Puppets(排序统计,水)
    188 Best Time to Buy and Sell Stock IV 买卖股票的最佳时机 IV
    187 Repeated DNA Sequences 重复的DNA序列
    179 Largest Number 把数组排成最大的数
    174 Dungeon Game 地下城游戏
  • 原文地址:https://www.cnblogs.com/nextseven/p/10482473.html
Copyright © 2011-2022 走看看