Created
June 25, 2018 08:35
-
-
Save rounakdatta/8f1f34f8ea316330ab713e0dcc4105b8 to your computer and use it in GitHub Desktop.
Get videos recorded on CodeNinja using Selenium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
driver = webdriver.Chrome() | |
usr = "" | |
pwd = "" | |
driver.get("http://www.facebook.org") | |
assert "Facebook" in driver.title | |
elem = driver.find_element_by_id("email") | |
elem.send_keys(usr) | |
elem = driver.find_element_by_id("pass") | |
elem.send_keys(pwd) | |
elem.send_keys(Keys.RETURN) | |
driver.get('http://codingninjas.in/app/classroom/online') | |
fb_login = driver.find_elements_by_class_name('button_container') | |
fb_login[1].click() | |
time.sleep(5) | |
driver.get('https://codingninjas.in/app/classroom/batch/115/wall') | |
time.sleep(5) | |
driver.get('https://codingninjas.in/app/classroom/me/141?batch_id=115') | |
driver.get('https://codingninjas.in/app/classroom/me/141/content/1911/offering/6565') | |
while(True) : | |
try: | |
# play the video | |
time.sleep(5) | |
driver.find_element_by_xpath('//*[@id="movie_player"]/div/div[27]/div[2]/div[1]/button[2]').click() | |
except: | |
print("couldn't find play button") | |
try: | |
# play the video in its full length | |
time.sleep(5) | |
total_vid_length = driver.find_element_by_xpath('//*[@id="movie_player"]/div/div[27]/div[2]/div[1]/div/span[3]').text | |
curr_vid_play = driver.find_element_by_xpath('//*[@id="movie_player"]/div/div[27]/div[2]/div[1]/div/span[1]').text | |
#total_time = int(total_vid_length.split(":")[0])*60 + int(total_vid_length.split(":")[1]) | |
#curr_time = int(curr_vid_play.split(":")[0])*60 + int(curr_vid_play.split(":")[1]) | |
print("total time : " + total_vid_length) | |
while(curr_vid_play != total_vid_length): | |
print(curr_vid_play) | |
curr_vid_play = driver.find_element_by_xpath('//*[@id="movie_player"]/div/div[27]/div[2]/div[1]/div/span[1]').text | |
'''while(curr_time < total_time): | |
print(curr_time) | |
curr_vid_play = driver.find_element_by_xpath('//*[@id="movie_player"]/div/div[27]/div[2]/div[1]/div/span[1]').text | |
curr_time = int(curr_vid_play.split(":")[0])*60 + int(curr_vid_play.split(":")[1])''' | |
# playback_time = int(total_vid_length.split(":")[0])*60 + int(total_vid_length.split(":")[1]) | |
# print("total video play time : " + str(playback_time)) | |
except Exception as e: | |
print(e) | |
print("video play error") | |
try: | |
# press the next button | |
time.sleep(30) | |
driver.find_element_by_xpath('/html/body/app-root/app-classroom-app/app-selected-content/div/div[2]/app-classroom-right-panel/div/app-content-footer/div/div/app-classroom-button[2]').click() | |
except: | |
print("next button not found") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment