Created
April 29, 2019 11:44
-
-
Save Kmaschta/b6e17a2b7f5620feb03c00674027467a to your computer and use it in GitHub Desktop.
Parse International Days
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
// https://www.journee-mondiale.com/les-journees-mondiales.htm | |
(() => { | |
const links = {}; | |
const articles = document.querySelectorAll('article'); | |
articles.forEach((article, monthIndex) => { | |
const items = article.querySelectorAll('li'); | |
items.forEach((li) => { | |
const t = li.querySelector('time').dateTime; | |
const date = t.split(' ')[0].replace('er', '') | |
const day = date.padStart(2, '0'); | |
const month = (monthIndex + 1).toString().padStart(2, '0'); | |
const text = li.querySelector('a').textContent.split(':')[1].trim() | |
const href = li.querySelector('a').getAttribute('href'); | |
if (!links[`${month}-${day}`]) { | |
links[`${month}-${day}`] = [] | |
} | |
links[`${month}-${day}`].push({ text, href }) | |
}) | |
}); | |
console.log(JSON.stringify(links, undefined, 4)) | |
})() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment