九色国产,午夜在线视频,新黄色网址,九九色综合,天天做夜夜做久久做狠狠,天天躁夜夜躁狠狠躁2021a,久久不卡一区二区三区

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
使用python Selenium實(shí)現(xiàn)智慧樹(shù)界面化自動(dòng)刷網(wǎng)課 chromehandless實(shí)現(xiàn)智慧樹(shù)無(wú)界面化自動(dòng)刷網(wǎng)課

      最近看到隔壁室友在學(xué)習(xí)python,再加上那句“爬蟲(chóng)學(xué)得好,監(jiān)獄進(jìn)的早”,于是有了一個(gè)大膽的想法,刷網(wǎng)課。我是通過(guò)使用selenium驅(qū)動(dòng)真實(shí)的瀏覽器來(lái)實(shí)現(xiàn)

        1.自動(dòng)點(diǎn)擊播放

        2.自動(dòng)切換到流暢畫(huà)質(zhì)(省流量)

        3.自動(dòng)1.5倍速

        4.自動(dòng)靜音

        4.自動(dòng)檢查當(dāng)前播放時(shí)間,結(jié)束后調(diào)到下一集

由于是驅(qū)動(dòng)真實(shí)的瀏覽器來(lái)實(shí)現(xiàn)一系列操作,所以理論上不會(huì)有封號(hào)危險(xiǎn) (祝你好運(yùn))

  1. # _*_ codeing utf-8 _*_
  2. # @TIME : 2021/11/6 22:30
  3. # @Author : wust Qiuyu
  4. # @File : test_selenium
  5. # @Project : 代碼
  6. from selenium import webdriver
  7. from selenium.webdriver.common.by import By
  8. import time
  9. from selenium.webdriver import ActionChains
  10. from selenium.webdriver.chrome.options import Options
  11. # 無(wú)界面
  12. def share_browser(): # 初始化
  13. chrome_options = Options()
  14. chrome_options.add_argument('--headless')
  15. chrome_options.add_argument('--disable-gpu')
  16. # 瀏覽器的安裝路徑 打開(kāi)文件位置 #這個(gè)路徑是你谷歌瀏覽器的路徑
  17. # chrome瀏覽器的安裝位置 Chromedriver需在當(dāng)前py文件的相同路徑下
  18. path = r'C:\Users\19436\AppData\Local\Google\Chrome\Application\chrome.exe'
  19. chrome_options.binary_location = path
  20. browser = webdriver.Chrome(chrome_options=chrome_options)
  21. return browser
  22. # 取消下方注釋即可使用有界面
  23. # # # # # # # # # # # # # # # # # # # # # #
  24. # 加載驅(qū)動(dòng) 有界面 #
  25. path = './chromedriver.exe' #
  26. browser = webdriver.Chrome(path) #
  27. # # # # # # # # # # # # # # # # # # # # # #
  28. # # # # # # # # # # # # # # # # # # # # # #
  29. # # 加載驅(qū)動(dòng) 無(wú)界面 #
  30. # browser = share_browser() #
  31. # # # # # # # # # # # # # # # # # # # # # #
  32. # 答題
  33. def response():
  34. try:
  35. #檢查是否有彈窗檢驗(yàn)
  36. browser.find_element(By.XPATH,'//div[@id="app"]/div[1]/div[7]/div[@class="el-dialog"]')
  37. option = browser.find_elements(By.XPATH, '//ul[@class="topic-list"]/li')
  38. for i in range(len(option)):
  39. option[i].click()
  40. # 獲取正確答案
  41. answer = browser.find_element(By.XPATH,"http://p[@class='answer']/span").text.split(',')
  42. print('正確答案是:' + str(answer))
  43. # 點(diǎn)擊正確答案
  44. for i in range(len(option)):
  45. print('選項(xiàng)'+str(i)+':'+option[i].text)
  46. flag=False
  47. for j in range(len(answer)):
  48. if option[i].text.find(answer[j])!=-1:
  49. flag=True
  50. break
  51. if(flag==False):
  52. option[i].click()
  53. # 點(diǎn)擊關(guān)閉
  54. close = browser.find_element(By.XPATH,'//div[@class="btn"]')
  55. close.click()
  56. print("答題成功!\t\t\t√")
  57. play()
  58. return True
  59. except:
  60. print("未找到彈窗測(cè)驗(yàn)\t\t?")
  61. return False
  62. # 點(diǎn)擊我知道了
  63. def clickIknow():
  64. try:
  65. # 檢測(cè)是否有我知道了
  66. browser.find_element(By.XPATH,'//div[@id="app"]/div[1]/div[6]')
  67. # 點(diǎn)擊我知道了
  68. iKnow = browser.find_element(By.XPATH,'//div[@id="app"]/div[1]/div[6]/div[1]/div[3]/span/button')
  69. iKnow.click()
  70. print("關(guān)閉我知道成功!\t√")
  71. return True
  72. except:
  73. print("未發(fā)現(xiàn)我知道了\t\t?")
  74. return False
  75. # 點(diǎn)擊學(xué)前必讀
  76. def clickBeforeRead():
  77. try:
  78. # 檢測(cè)是否有學(xué)前必讀
  79. browser.find_element(By.XPATH,'//div[@id="app"]/div[1]/div[7]')
  80. # 點(diǎn)擊×
  81. close = browser.find_element(By.XPATH,'//div[@id="app"]/div[1]/div[7]/div[2]/div[1]/i')
  82. close.click()
  83. print("關(guān)閉學(xué)前必讀成功!\t√")
  84. return True
  85. except:
  86. print("未發(fā)現(xiàn)學(xué)前必讀\t\t?")
  87. return False
  88. # 獲取當(dāng)前播放時(shí)間
  89. def getCurrentTime():
  90. openControlsBar()
  91. time = browser.find_element(By.XPATH,'//div[@class="nPlayTime"]/span[1]').text
  92. print('當(dāng)前播放時(shí)間為:'+time)
  93. return time
  94. # 獲取當(dāng)前視頻總時(shí)間
  95. def getTotalTime():
  96. openControlsBar()
  97. time = browser.find_element(By.XPATH,'//div[@class="nPlayTime"]/span[2]').text
  98. print('本集視頻時(shí)間為:' + time)
  99. return time
  100. # 播放下一個(gè)視頻
  101. def nextVideo():
  102. openControlsBar()
  103. nextBtn = browser.find_element(By.XPATH,'//div[@id="nextBtn"]')
  104. nextBtn.click()
  105. print('\n切換下一個(gè)視頻\n')
  106. # 1.5速度
  107. def fasterPlay():
  108. try:
  109. openControlsBar()
  110. speed = browser.find_element(By.XPATH,' //div[@class="speedBox"]/div/div[1]')
  111. speedbox = browser.find_element(By.XPATH,'//div[@class="speedBox"]')
  112. time.sleep(5)
  113. openControlsBar()
  114. ActionChains(browser).move_to_element(speedbox).perform()
  115. speed.click()
  116. print('成功切換成'+speed.text+'倍速\t√')
  117. except:
  118. print('切換成' + speed.text + '倍速失敗,稍后將重試\t?')
  119. # 點(diǎn)擊開(kāi)始播放
  120. def play():
  121. start_status = browser.find_element(By.XPATH,'//div[@id="playButton"]').get_attribute('class')
  122. start_button = browser.find_element(By.XPATH,'//div[@id="playButton"]')
  123. time.sleep(10)
  124. if start_status.find('playButton')!=-1:
  125. print('當(dāng)前靜止')
  126. openControlsBar()
  127. time.sleep(1)
  128. start_button.click()
  129. print('點(diǎn)擊播放成功\t\t√')
  130. # 點(diǎn)擊靜音
  131. def noVoice():
  132. try:
  133. voice_status = browser.find_element(By.XPATH,'//div[@id="vjs_container"]/div[10]/div[6]').get_attribute('class')
  134. voice_buttton= browser.find_element(By.XPATH,'//div[@id="vjs_container"]/div[10]/div[6]/div[1]')
  135. print(voice_status)
  136. if voice_status.find('volumeNone')==-1:
  137. print('此時(shí)非靜音')
  138. time.sleep(5)
  139. openControlsBar()
  140. voice_buttton.click()
  141. print('靜音成功\t\t\t√')
  142. except:
  143. print('靜音失敗,稍后將重試\t\t?')
  144. # 切換流暢畫(huà)質(zhì)
  145. def changeVideoQuality():
  146. try:
  147. openControlsBar()
  148. videoQuality = browser.find_element(By.XPATH,' //div[@class="definiBox"]/div/b[1]')
  149. definiBox = browser.find_element(By.XPATH,' //div[@class="definiBox"]')
  150. time.sleep(5)
  151. openControlsBar()
  152. ActionChains(browser).move_to_element(definiBox).perform()
  153. videoQuality.click()
  154. print('成功切換到流暢畫(huà)質(zhì)\t√')
  155. checkWindow()
  156. except:
  157. print('切換到流暢畫(huà)質(zhì)失敗,稍后將重試\t\t?')
  158. # 打開(kāi)ControlsBar
  159. def openControlsBar():
  160. checkWindow()
  161. controlsBar = browser.find_element(By.XPATH,' //div[@id="container"]')
  162. ActionChains(browser).move_to_element(controlsBar).perform()
  163. # 檢測(cè)彈窗
  164. def checkWindow():
  165. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'正在播放:'+getUnitName())
  166. clickIknow()
  167. clickBeforeRead()
  168. response()
  169. print('\n\n')
  170. # 獲取當(dāng)前章節(jié)
  171. def getUnitName():
  172. try:
  173. name = browser.find_element(By.XPATH,'//*[@id="app"]/div/div[2]/div[1]/div[1]/div[1]')
  174. return name.text
  175. except:
  176. return '暫未加載'
  177. if __name__ == '__main__':
  178. # 訪問(wèn)網(wǎng)站 課程的地址
  179. url = 'https://studyh5.zhihuishu.com/videoStudy.html#/studyVideo?recruitAndCourseId=4b595c5c435d4859454a5859584259455f'
  180. # 賬號(hào)密碼
  181. userName = "**************"
  182. passWord = "**************"
  183. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'開(kāi)始學(xué)習(xí)\n')
  184. browser.get(url)
  185. # 元素定位 輸入用戶名密碼
  186. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'正在輸入賬號(hào)\n')
  187. inputUsername = browser.find_element(By.XPATH,'//input[@id="lUsername"]')
  188. inputUsername.send_keys(userName)
  189. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'賬號(hào)輸入成功\n')
  190. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'正在輸入密碼\n')
  191. inputPassword = browser.find_element(By.XPATH,'//input[@id="lPassword"]')
  192. inputPassword.send_keys(passWord)
  193. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'密碼輸入成功\n')
  194. # 點(diǎn)擊登錄
  195. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'正在登陸\n')
  196. login = browser.find_element(By.XPATH,"http://span[@class='wall-sub-btn']")
  197. login.click()
  198. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'登陸成功\n')
  199. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'正在進(jìn)入課程\n\n')
  200. print('----------------------------------')
  201. import threading
  202. from threading import Lock,Thread
  203. import time,os
  204. while(True):
  205. # 有時(shí)進(jìn)入視頻會(huì)直接彈出窗口,且窗口顯示順序不定,故檢測(cè)三次,保證再開(kāi)始播放之前關(guān)閉
  206. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n'+'正在在執(zhí)行視頻播放前檢查')
  207. for i in range(3):
  208. print('\n第' + str(i) + '檢測(cè)')
  209. checkWindow()
  210. time.sleep(2)
  211. print(time.strftime('%Y-%m-%d %H:%M:%S')+'\n檢查完畢\n\n\n開(kāi)始優(yōu)化播放\n')
  212. # 避免在前三次中未檢測(cè)出窗口,開(kāi)始操作前全部檢查一次
  213. checkWindow()
  214. play()
  215. print('正在修改畫(huà)質(zhì)')
  216. time.sleep(2)
  217. checkWindow()
  218. changeVideoQuality()
  219. print('畫(huà)質(zhì)修改成功\t\t\t√')
  220. print('正在修該播放速度')
  221. checkWindow()
  222. fasterPlay()
  223. print('播放速度修改成功\t\t\t√')
  224. print('正在修改靜音')
  225. checkWindow()
  226. noVoice()
  227. print('靜音修改成功\t\t√\n\n')
  228. # 每隔5秒檢測(cè)是否有我知道了,學(xué)前必讀,是否播放完
  229. while(True):
  230. print(time.strftime('%Y-%m-%d %H:%M:%S'))
  231. # 播放完畢,下一集
  232. if getCurrentTime() == getTotalTime():
  233. print('\n\n')
  234. checkWindow()
  235. nextVideo()
  236. break
  237. print('\n\n')
  238. checkWindow()
  239. print('\n\n')
  240. time.sleep(5)

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
實(shí)戰(zhàn) | 教你快速爬取熱門(mén)股票,輔助量化交易!
從零開(kāi)始Web自動(dòng)化(三):通過(guò)selenium,9行代碼實(shí)現(xiàn)打字網(wǎng)站的自動(dòng)打字
selenium 反爬蟲(chóng)之跳過(guò)淘寶滑塊驗(yàn)證(2020/8)
使用Selenium WebDriver,Python和Chrome編寫(xiě)您的第一個(gè)Web測(cè)試
Python 爬蟲(chóng)(四):Selenium 框架
用selenium實(shí)現(xiàn)某微博搜索數(shù)據(jù)的抓取
更多類似文章 >>
生活服務(wù)
熱點(diǎn)新聞
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服