Created
April 5, 2019 06:42
-
-
Save ghulamMustafaRaza/511ed62d05c8065725db20c14c8c9c90 to your computer and use it in GitHub Desktop.
Udemy Details Scrapper JavaScript
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
var sections = new Array(...document.querySelectorAll('.ud-component--clp--curriculum>div')).filter(a => !a.className); | |
var more = document.querySelector('.section-container.section-container--more-sections') | |
more && more.click() | |
sections.map(section => { | |
let a = section.querySelector('a'); | |
let lacturesC = section.querySelector('.lectures-container.collapse'); | |
if (lacturesC.classList.contains('in')) a.click() | |
}) | |
setTimeout(() => { | |
var results = sections.map(section => { | |
let a = section.querySelector('a'); | |
let parts = a.innerText.split('\n').slice(1); | |
let lacturesC = section.querySelector('.lectures-container.collapse'); | |
let result = { | |
title: parts[0], | |
count: parseInt(parts[1].split(' ')[0]), | |
duration: toSeconds(parts[2]) | |
} | |
if (!(lacturesC.classList.contains('in'))) a.click() | |
result.lectures = [...lacturesC.querySelectorAll('.lecture-container')].map(c => { | |
let parts = c.innerText.split('\n') | |
return { | |
title: parts[0], | |
duration: toSeconds(parts[parts.length - 1]) | |
} | |
}) | |
return result | |
}) | |
function toSeconds (hms) { | |
var a = ['00', '00', '00'].concat(hms.split(':')).slice(-3); // split it at the colons | |
console.log(a) | |
// minutes are worth 60 seconds. Hours are worth 60 minutes. | |
return (+a[0]) * 60 * 60 + (+a[1]) * 60 + (+a[2]) | |
} | |
console.log(results) | |
}, 1000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment