Skip to content

Instantly share code, notes, and snippets.

@rakshakhegde
Last active May 8, 2017 10:22
Show Gist options
  • Save rakshakhegde/1a7176fec9de1d1e1286896fd07ba9f7 to your computer and use it in GitHub Desktop.
Save rakshakhegde/1a7176fec9de1d1e1286896fd07ba9f7 to your computer and use it in GitHub Desktop.
import time
from selenium import webdriver
import csv
import urllib.request
driver = webdriver.Chrome()
driver.implicitly_wait(5)
base_url = "https://baseurl/login/"
verificationErrors = []
accept_next_alert = True
# open home page
driver.get(base_url)
# Login
driver.find_element_by_id("rcp_user_login").clear()
driver.find_element_by_id("rcp_user_login").send_keys("rakshakhegde")
time.sleep(5) # enter password here
driver.find_element_by_id("rcp_user_remember").click()
driver.find_element_by_id("rcp_login_submit").click()
# Get urls from csv
reader = csv.reader(open('caster-lesson-list.csv'), delimiter=',', quotechar='"')
for row in list(reader)[113:]:
lessonName = row[1]
lessonLink = row[2]
driver.get(lessonLink)
# time.sleep(2)
#
# try:
# driver.find_element_by_id("wistia_28_requireEmail_skip").click()
# except:
# try:
# driver.find_element_by_class_name("wistia_responsive_padding").click()
# time.sleep(5)
# driver.find_element_by_class_name("wistia_responsive_padding").click()
# except:
# continue
vidLink = driver.find_element_by_tag_name('source').get_attribute('src')
dashedLessonName = lessonName.replace('/', '-')
print(dashedLessonName, vidLink)
urllib.request.urlretrieve(vidLink, 'videos/' + dashedLessonName + '.mp4')
time.sleep(5) # Let the user actually see something!
driver.quit()
import time
from selenium import webdriver
import csv
import urllib.request
mobile_emulation = {
"deviceMetrics": {"width": 1024, "height": 768, "pixelRatio": 2.0},
"userAgent": "Mozilla/5.0 (iPad; CPU OS 10_2_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/57.0.2987.100 Mobile/14D27 Safari/602.1"
}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.implicitly_wait(5)
base_url = "https://caster.io/login/"
verificationErrors = []
accept_next_alert = True
# open home page
driver.get(base_url)
# Login
driver.find_element_by_id("rcp_user_login").clear()
driver.find_element_by_id("rcp_user_login").send_keys("rakshakhegde")
time.sleep(5) # enter password here
driver.find_element_by_id("rcp_user_remember").click()
driver.find_element_by_id("rcp_login_submit").click()
# Get urls from csv
reader = csv.reader(open('casterio-updated.csv'), delimiter=',', quotechar='"')
readerList = list(reader)
readerListSize = len(readerList)
print('readerList size:', readerListSize)
for i, row in enumerate(readerList[:15]):
lessonName = f'Lesson {readerListSize-i}: ' + row[1].replace('/', '-')
lessonLink = row[2]
driver.get(lessonLink)
time.sleep(2)
vidLink = driver.find_element_by_tag_name('source').get_attribute('src')
print(lessonName, vidLink)
urllib.request.urlretrieve(vidLink, 'videos/' + lessonName + '.mp4')
time.sleep(5) # Let the user actually see something!
driver.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment