Skip to content

Commit

Permalink
Merge pull request #3298 from marcode24/challenge-18
Browse files Browse the repository at this point in the history
Reto #18 - Javascript
  • Loading branch information
Roswell468 authored May 2, 2023
2 parents 3c754da + 25be157 commit 5792947
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Retos/Reto #18 - WEB SCRAPING [Difícil]/javascript/marcode24.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* El día 128 del año celebramos en la comunidad el "Hola Mundo day"
* Vamos a hacer "web scraping" sobre su sitio web: https://holamundo.day
*
* Crea un programa que se conecte a la web del evento e imprima únicamente la agenda de eventos
* del día 8. Mostrando hora e información de cada uno.
* Ejemplo: "16:00 | Bienvenida"
*
* Se permite utilizar librerías que nos faciliten esta tarea.
*
*/

const puppeteer = require('puppeteer');

const SITE = 'https://holamundo.day/';

const getShedule = async () => {
const browser = await puppeteer.launch({
headless: 'new',
});
const page = await browser.newPage();
await page.goto(SITE);
const title = await page.title();
const content = await page.$$('article.notion-page-content-inner');
const events = content[7]; // 7 is the index of the events section

const quoteElements = await events.$$('blockquote.notion-quote');
const eventInfo = await Promise.all(quoteElements.map(async (quoteElement) => {
const spanElement = await quoteElement.$('span[data-slate-string="true"]');
const text = await quoteElement.evaluate((el) => el.textContent, spanElement);
return text;
}));
const schedule = `${title}\n\n`.concat(eventInfo
.map((event) => event.replace(/\n/g, ' '))
.join('\n'));
if (browser) await browser.close();
return schedule;
};

getShedule().then((schedule) => console.log(schedule));

// Visita mi repo en GitHub para ver y correr los tests de este código --> https://github.com/marcode24/weekly-challenges

0 comments on commit 5792947

Please sign in to comment.