Skip to content

Instantly share code, notes, and snippets.

@uratmangun
Last active December 26, 2024 01:59
Show Gist options
  • Save uratmangun/0cf8288bdd263488014f3b8fa926c24c to your computer and use it in GitHub Desktop.
Save uratmangun/0cf8288bdd263488014f3b8fa926c24c to your computer and use it in GitHub Desktop.
async function getCategories(page) {
console.log('Navigating to https://alfagift.id/');
await page.goto('https://alfagift.id/');
console.log('Waiting for response...');
// Wait for the specific categories menu container
// await page.waitForSelector('//*[@id="__layout"]/div/div[1]/header[1]/div[2]/div/div/div[1]/div[1]/div/div/div/div[2]/div/div/div');
// Get and log the content of the categories container
const containerContent = await page.evaluate(() => {
const container = document.evaluate(
'//*[@id="__layout"]/div/div[1]/header[1]/div[2]/div/div/div[1]/div[1]/div/div/div/div[2]/div/div/div',
document,
null,
XPathResult.FIRST_ORDERED_NODE_TYPE,
null
).singleNodeValue;
const links = container.getElementsByTagName('a');
const linkData = [];
for (const link of links) {
linkData.push({
href: link.href,
text: link.innerText,
});
}
return linkData;
});
return containerContent;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment