Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ilhamgusti/cd7cba57d83010176a0d1f3b8aff3414 to your computer and use it in GitHub Desktop.
Save ilhamgusti/cd7cba57d83010176a0d1f3b8aff3414 to your computer and use it in GitHub Desktop.
// Full TypeScript support for both puppeteer and the DOM
export default async ({ page }: { page: Page }) => {
// Full puppeteer API is available
const url = 'https://holidayapi.com/countries/id/2025';
await page.goto(url, {waitUntil: 'networkidle0'});
const data = await page.evaluate(()=>{
const query = (selector, context) => Array.from(context.querySelectorAll(selector));
const result = query('tr', document).map(row => query('td, th', row).map(cell => cell.innerText + " " + (cell.getAttribute('style')?.includes("font-weight: 900;") ? "[RED]":'')))
const [dateKey,dayKey,labelKey,noteKey] = result[0];
const datas = result.slice(1)
const json = datad.map(([date,day,label,note]) =>{
return {
[dateKey.trim().toLowerCase()]:date.replace(" [RED]",""),
[dayKey.trim().toLowerCase()]:day.replace(" [RED]",""),
national_holiday: day.includes("[RED]"),
[labelKey.trim().toLowerCase()]:label.replace(" [RED]",""),
[noteKey.trim().toLowerCase()]:note,
}
})
return {result,keys:result[0],datas,json}
})
// Logs show up in the browser's devtools
console.log(`I show up in the page's console!`);
console.log({data})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment