Skip to content

Instantly share code, notes, and snippets.

@paquette-dev
Last active January 9, 2025 17:26
Show Gist options
  • Save paquette-dev/85b3fb5b5d1d81fd2a4475b3cdde8fd3 to your computer and use it in GitHub Desktop.
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
(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