-
-
Save paquette-dev/85b3fb5b5d1d81fd2a4475b3cdde8fd3 to your computer and use it in GitHub Desktop.
A utility to parse a udemy course and collect each sub-section for each course section
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
| (function() { | |
| const COURSE_SECTION_SELECTOR = ".accordion-panel-module--panel--Eb0it.section--panel--qYPjj"; | |
| const COURSE_SECTION_LABEL_SELECTOR = ".section--section-title--svpHP"; | |
| const COURSE_SECTION_TOGGLER_SELECTOR = ".accordion-panel-module--panel-toggler--WUiNu.accordion-panel-module--outer-panel-toggler--Pxwxc"; | |
| const COURSE_SECTION_SUB_SECTION_LABEL_SELECTOR = ".section--item-title--EWIuI"; | |
| const courseSections = document.querySelectorAll(COURSE_SECTION_SELECTOR); | |
| const courseSectionArr = [...courseSections]; | |
| const courseSectionLabels = courseSectionArr.map((courseSection) => { | |
| const isCourseSectionOpened = courseSection.firstChild.dataset.checked === "checked"; | |
| if (!isCourseSectionOpened) { | |
| const courseSectionToggler = courseSection.querySelector(COURSE_SECTION_TOGGLER_SELECTOR); | |
| if (courseSectionToggler) { | |
| courseSectionToggler.click(); | |
| } | |
| } | |
| const courseSubSections = courseSection.querySelectorAll(COURSE_SECTION_SUB_SECTION_LABEL_SELECTOR); | |
| const courseSubSectionsArr = [...courseSubSections]; | |
| const courseSubSectionLabels = courseSubSectionsArr.map((label) => label.innerText); | |
| const courseSectionTitle = courseSection.querySelector(COURSE_SECTION_LABEL_SELECTOR).innerText; | |
| return { | |
| courseSectionTitle, | |
| courseSubSectionLabels | |
| }; | |
| }); | |
| return courseSectionLabels; | |
| })() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment